discord.py 机器人的问题

Problems with a discord.py bot

我一直在尝试为我自己的服务器编写一个 Discord 机器人。 但是,似乎每当我向代码中添加更多命令时,禁止和踢功能就不再正常工作。 我试过多次重写代码,但没有成功。 我试过重新排列代码,但效果不佳。

client = commands.Bot(command_prefix = '!')

@client.command()
async def kick(ctx, member : discord.Member, *, reason = None):
  await member.kick(reason = reason)

@client.command()
async def ban(ctx, member : discord.Member, *, reason = None):
  await member.ban(reason = reason)


curseWord = ['die', 'kys', 'are you dumb', 'stfu', 'fuck you', 'nobody cares', 'do i care', 'bro shut up']

def get_quote():
  response = requests.get("https://zenquotes.io/api/random")
  json_data = json.loads(response.text)
  quote = json_data[0]['q'] + " -" + json_data[0]['a']
  return(quote)

#ready
@client.event
async def on_ready():
  print('LOGGED IN as mr MF {0.user}'.format(client))

@client.event
#detect self messages
async def on_message(message):
  if message.author == client.user:
    return
  #greeting
  if message.content.startswith('hello'):
    await message.channel.send('ay whatup ma gamer')
  #help
  if message.content.startswith('!therapy'):
    quote = get_quote()
    await message.channel.send(quote)
  #toxicity begone
  msg_content = message.content.lower()

  if any(word in msg_content for word in curseWord):
    await message.delete()

    
#environment token
token = os.environ['token']

client.run(token)

您已经覆盖了 on_message 事件,该事件默认处理命令(那些标有 @client.command() 装饰器的命令)。当你覆盖它时,你需要明确地告诉库处理命令。如 the discord.py documentation 中所述,您应该在 on_message 事件的末尾添加此行:

await client.process_commands(message)