Python Bot 命令不起作用,但事件是

时间:2021-07-14 23:26:30

标签: python discord discord.py

命令不起作用,但尝试覆盖我的 on_message 事件,但这没有用。当我注释掉第二个 client.event 和向下 client.command 时。知道我可能做错了什么吗?我错过了什么吗?

import discord
from discord.ext import commands
import random
import time 
from datetime import date

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

#client = discord.Client()



@client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))


@client.command()
async def clr(ctx, amount=5):
   await ctx.channel.purge(limit=amount)



@client.command(aliases =['should', 'will'])
async def _8ball(ctx):
    responses =['As i see it, yes.',
                'Ask again later.',
                'Better not tell you now.',
                "Don't count on it",
                'Yes!']
    await ctx.send(random.choice(responses))


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

  if message.content.startswith('hello'):
     await message.channel.send('Hello how are you?')
    

1 个答案:

答案 0 :(得分:1)

基于 the docs(moinierer3000 在评论中提到的那些)以及堆栈上的其他问题(如下所列),如果您不处理命令,on_message 将停止您的命令工作.

@client.event()
async def on_message(message):
  if message.author == client.user:
     return
  if message.content.startswith('hello'):
     await message.channel.send('Hello how are you?')
  await client.process_commands(message)

其他类似问题