如何在python中创建一个autorole bot(discord.py)

时间:2017-11-02 20:22:01

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

代码需要能够自动分配角色' Noobies'和角色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.")

1 个答案:

答案 0 :(得分:0)

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

也许你需要将它传递给函数并避免尝试依赖它作为global