从所有命令获得单个响应

时间:2018-07-21 05:36:48

标签: python-3.x discord.py

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

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

1 个答案:

答案 0 :(得分:0)

您可以在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')