【问题标题】:Python Bot command not working but event isPython Bot 命令不起作用,但事件是
【发布时间】:2021-09-23 21:47:25
【问题描述】:

命令不起作用,但尝试覆盖我的 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?')
    

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

基于the docs(在 cmets 中 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)

类似的其他问题

【讨论】:

    猜你喜欢
    • 2021-12-30
    • 1970-01-01
    • 2020-08-16
    • 2019-07-23
    • 1970-01-01
    • 2020-12-24
    • 2021-11-19
    • 2018-07-28
    • 1970-01-01
    相关资源
    最近更新 更多