【问题标题】:Discord.py text to assign roleDiscord.py 文本分配角色
【发布时间】:2021-03-17 23:27:31
【问题描述】:

我已经在构建一个 discord.py 机器人。但是,我想让它在不使用特定频道中的前缀的情况下分配角色 - 我的意思是在 #roles 频道中。如果成员写了"Mage",并且已经创建了Mage 角色,bot 会将角色分配给成员。我寻找一个反应角色,但我需要更具体的东西。我正在等待您的想法和帮助。祝你有美好的一天!

【问题讨论】:

  • 欢迎来到 StackOverflow。这不是我们为您编写代码的免费服务。您必须亲自尝试并向我们展示您所做的工作,我们可以一路提供帮助。阅读how to ask 一个好问题!对于你的问题本身,也许this可以给你一点指导
  • 很抱歉要求为我编写代码。我知道它很懒,但我尝试了很多并且搜索找不到它。我记住下一个问题。

标签: python discord bots discord.py


【解决方案1】:
@client.event
async def on_message(message): # Using on_message event reference you dont need to have a prefix
    guild = message.author.guild
    if message.content.lower() == "what the message name should be":  # Checks if the WHOLE message is that one word, so not if that one word was part of a message
        role = discord.utils.get(guild.roles, name="role name") # Gets the role
        if role is not None: # makes sure role exists
            await message.author.add_roles(role) # Assigns role to the message author

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 2019-10-20
    • 2021-09-30
    • 1970-01-01
    • 2021-04-08
    • 2021-04-17
    相关资源
    最近更新 更多