【问题标题】:How do I make my Bot Ignore messages from people with a certain role? (Discord.py)如何让我的机器人忽略来自具有特定角色的人的消息? (不和谐.py)
【发布时间】:2021-10-09 17:32:57
【问题描述】:

如何让我的 Discord.py 机器人忽略来自具有特定角色的人的消息?

我最近为我的 Discord.py 机器人添加了一项功能。

@client.event
async def on_message(message):

    if message.content == "Blocked Word":
        await message.delete()

我想要这样,如果这样的人拥有我自己,具有特定角色,机器人不会删除该消息。

任何帮助将不胜感激!

【问题讨论】:

  • 您可以使用message.author.roles获取成员角色列表

标签: python discord discord.py bots roles


【解决方案1】:

这里有一些简单的代码,可能会回答您的问题: 这建立在@Joshua Nixon 的回答之上

@client.event()
async def on_message(message):
 if 'role' in [role.name for role in message.author.roles]: #checks if the specified role is in the user's roles
   #do something
 else:
   #do something else

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 2021-06-13
    • 2020-12-26
    • 1970-01-01
    • 2020-11-18
    • 2019-07-11
    • 2021-03-03
    相关资源
    最近更新 更多