Discord.py 审核活动

Discord.py moderation event

@client.event
async def on_message(message):
    if message.content.startswith('Some bad word'):
        guild = ctx.guild
        await message.channel.send(f'%s, ou, you said bad word. I have to mute you for 1 hour.')
        mutedRole = discord.utils.get(guild.roles, name='Muted')
        await member.add_role(mutedRole)
        await asyncio.sleep(3600)
        await member.remove_roles(mutedRole)

大家好!我不能创建一个事件,谁静音了一个成员,谁在聊天中写了一个坏词,因为 on_message 不接受参数 member, ctx 等等。我应该怎么做才能创建这个“适度”事件?

请查看文档,message 拥有您需要的一切。您可以将 ctx.guild 替换为 message.guild,将 member 替换为 message.author

https://discordpy.readthedocs.io/en/master/api.html?highlight=message#discord.Message

guild = message.guild
await message.channel.send(f'%s, ou, you said bad word. I have to mute you for 1 hour.')
mutedRole = discord.utils.get(guild.roles, name='Muted')
await message.author.add_role(mutedRole)
await asyncio.sleep(3600)
await message.author.remove_roles(mutedRole)