Python 3.x 从所有命令中获取单个响应

Python 3.x 从所有命令中获取单个响应,python-3.x,discord.py,Python 3.x,Discord.py,当用户使用任何命令时,如何使bot发送特定消息。所以当用户使用时!ping或任何它应该发送默认消息的命令。有一段时间我需要停止机器人对除1个命令以外的所有命令的响应 @bot.command(pass_context=True) async def ping(ctx): msg = "Pong {0.author.mention}".format(ctx.message) await bot.say(msg) 您可以在on_message事件中执行此操作。下面是示例代码 fro

当用户使用任何命令时,如何使bot发送特定消息。所以当用户使用
时!ping
或任何它应该发送默认消息的命令。有一段时间我需要停止机器人对除1个命令以外的所有命令的响应

@bot.command(pass_context=True)
async def ping(ctx):
    msg = "Pong {0.author.mention}".format(ctx.message)
    await bot.say(msg)

您可以在
on_message
事件中执行此操作。下面是示例代码

from discord.ext import commands

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

@client.event
async def on_ready():
    print('client ready')

@client.command(pass_context=True)
async def ping(ctx):
    msg = "Pong {0.author.mention}".format(ctx.message)
    await bot.say(msg)

@client.event
async def on_message(message):
    if message.startswith(bot_prefix):
        await client.send_message(message.channel, 'Processing commands')

    await client.process_commands(message)

client.run('TOKEN')

如果我有两个机器人它不会坏吗
@client.event
@bot.event
我们可以在
@bot.event
中添加
如果message.startswith(bot\u前缀)
,则必须查看完整的代码才能确定,但不要认为它会破坏任何东西。最好的确定方法是测试。