是否可以在同一代码中使用on_message和@ client.command?

时间:2020-06-02 11:18:56

标签: events command discord.py-rewrite

我试图制造一个不和谐的机器人。但是,我的某些命令必须在过时的on_message事件中执行,因为它们在命令扩展名下将无法工作。我需要添加任何代码行来使命令扩展同时工作。我的意思是我有一些on_message事件,当我在代码末尾添加@client.command时,@client.command命令将不会响应。

这是我在此处尝试实现的示例代码。

@client.event
async def on_message(message):
    if message.content.startswith('ggg'):
        print('hello')
    elif message.content.startswith('hello')
        print('hello')

@client.command()
async def example():
    print('hello')

显然,该代码将得到进一步开发。那只是一个例子。

1 个答案:

答案 0 :(得分:1)

当然可以。您只需要知道await client.process_commands(message)。在discord.py docs中,您可以了解此问题。

也请检查以下内容:on_message() and @bot.command issue

相关问题