【问题标题】:After @bot event other commands do not work在@bot 事件之后,其他命令不起作用
【发布时间】:2021-12-30 02:16:42
【问题描述】:

我有这样的代码:

@bot.command(pass_context=True)
@commands.has_any_role(admin, moderator, ghostluko)
async def ver(ctx,member:discord.Member = None):
    role = ctx.guild.get_role(role_id=868210259284619324)
    role1 = ctx.guild.get_role(role_id=905358001270046770)
    await ctx.message.delete()
    await member.add_roles(role)
    await member.remove_roles(role1)
    await ctx.send(f'{member} дал роль "{role}"') 

我添加后,其他命令启动不起作用

@bot.event
async def on_message(message):

    embedbotreply = discord.Embed(description = f"Напишите help для подробной информации. Ваш префикс: {bot.command_prefix}", color = 0x8147fc)

    if bot.user.mentioned_in(message):
        await message.channel.send(embed = embedbotreply)

@bot.command()
async def ping(ctx):

    embedping = discord.Embed(description = f" Мой пинг: {format(round(bot.latency, 1))} ms!", color = 0x8147fc)

    await ctx.send(embed = embedping)
    await ctx.message.delete()

另外,on_member_join 不起作用。我不知道该怎么办。

【问题讨论】:

标签: discord discord.py bots


【解决方案1】:
 @bot.event
 async def on_message(message):
      if message.author==bot.user: 
        return

      await bot.process_commands(message)

尝试在您的代码中使用await bot.process_commands(message),在此代码之后您可以使用其他命令:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!")


@bot.event
async def on_ready():
  print('We are logged in!')

@bot.event
async def on_message(message):
   if message.author==bot.user: 
     return

   await bot.process_commands(message)

@bot.command()
async def ping(message) :
   await message.channel.send("Pong!!")

bot.run("TOKEN")

希望对你有帮助!!

【讨论】:

  • 你的东西不起作用。机器人只是不回应:(
  • @Maron 我希望您在代码中使用了您的机器人令牌,因为此代码对我来说可以正常工作。
  • 是的,我在主文件中使用了 bot.run
猜你喜欢
  • 2021-09-23
  • 2020-08-16
  • 2019-07-23
  • 1970-01-01
  • 2020-12-24
  • 2013-02-12
  • 2021-11-19
  • 2018-07-28
  • 2020-10-04
相关资源
最近更新 更多