【问题标题】:How to make an autorole bot in python (discord.py)如何在 python (discord.py) 中制作自动角色机器人
【发布时间】:2018-04-15 11:48:25
【问题描述】:

代码需要能够自动将角色“Noobies”和角色“Level 0”分配给每个新加入者。我一直在尝试调整我的代码,从使用命令到让它在有人自动加入时分配一个角色,但是我认为 message.server.roles 正在把它扔掉,我不知道如何修复它。这是我的第一个机器人,所以请温柔。

@bot.async_event  

async def on_member_join(Member : discord.User):  

    roles = [
        # IDs of the roles for the teams
        "333674108799942666",
        "351957337453363204",
    ]

    team_list = ["Noobies", "Level 0"]
    #entered_team = message.content[6:].lower()
    for team in team_list:

        role = discord.utils.get(message.server.roles, name=team)
        try:
            await client.add_roles(Member.name, role)
        except Exception as e:
                await bot.send_message(bot.get_channel("channel id"),'IT DIDNT WORK AHHH CONTACT SUPERDUPERDOOKEN OR EMI-SAN! and say: '+str(e))                
            #await client.send_message(message.channel, "Successfully added role {0}".format(role.name))
        #except discord.Forbidden:
            #await client.send_message(message.channel, "I don't have perms to add roles.")

【问题讨论】:

  • 查看参数及其属性的文档

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


【解决方案1】:

message 似乎没有在函数中定义。

也许您需要将其传递给函数并避免尝试将其作为global 来依赖。

【讨论】:

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