如何在python(discord.py)中创建自动角色机器人
代码需要能够自动将角色“Noobies”和角色“Level 0”分配给每个新加入者。我一直在尝试调整我的代码,从使用命令到让它在有人自动加入时分配角色,但是我认为message.server.roles正在抛出它,我不知道如何修复它。这是我的第一个机器人,所以请温柔一点如何在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
@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.")
消息
似乎未在函数中定义
也许您需要将其传递到函数中,并避免试图将其作为
全局
查看文档中的参数及其属性