Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python(discord.py)中创建自动角色机器人_Python_Python 3.x_Python Asyncio_Discord_Discord.py - Fatal编程技术网

如何在python(discord.py)中创建自动角色机器人

如何在python(discord.py)中创建自动角色机器人,python,python-3.x,python-asyncio,discord,discord.py,Python,Python 3.x,Python Asyncio,Discord,Discord.py,代码需要能够自动将角色“Noobies”和角色“Level 0”分配给每个新加入者。我一直在尝试调整我的代码,从使用命令到让它在有人自动加入时分配角色,但是我认为message.server.roles正在抛出它,我不知道如何修复它。这是我的第一个机器人,所以请温柔一点 @bot.async_event async def on_member_join(Member : discord.User): roles = [ # IDs of the roles f

代码需要能够自动将角色“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.")

消息
似乎未在函数中定义


也许您需要将其传递到函数中,并避免试图将其作为
全局

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