on_message 事件禁用所有机器人命令

时间:2020-12-28 07:12:43

标签: python python-3.x discord discord.py

我有一个 on_message 事件来阻止具有“静音”角色的用户发送消息:

@client.event
async def on_message(ctx):
    muted=ctx.author.guild.get_role(673180122768998411)
    if muted in ctx.author.roles:
        await ctx.message.delete()

但是有了这个事件,机器人不会对所有命令做出反应。他们不工作。 示例命令:

@client.command(passContent = True)
@commands.has_role("?║Участники")
async def rank(ctx):
    return

1 个答案:

答案 0 :(得分:1)

你必须使用这个:

await client.process_commands(ctx)

因此,您的活动将如下所示:

@client.event
async def on_message(ctx):
    muted = ctx.author.guild.get_role(673180122768998411)
    if muted in ctx.author.roles:
        await ctx.delete()

    await client.process_commands(ctx)