简体   繁体   English

尝试使用 Discord.py 重写来制作自动角色 discord 机器人

[英]Trying to make an autorole discord bot using Discord.py rewrite

I am trying to make an bot that as soon as a member joins, automatically gives them a role.我正在尝试制作一个机器人,一旦成员加入,就会自动给他们一个角色。 This is my code and I can't seem to work out what the problem is.这是我的代码,我似乎无法解决问题所在。 Hopefully someone more smart and experienced can help me希望更聪明和有经验的人可以帮助我

@client.event
async def on_member_join(member):
    role = get(member.guild.roles, name = ROLE)
    await member.add_roles(role)
    print(f'{member} was given {role}')

As the event is not producing any errors, it most likely means it's an issue with member intents.由于该事件没有产生任何错误,这很可能意味着它是成员意图的问题。

Any events to do with members will require these intents to be enabled from the Discord developer portal and defined in your code.与成员有关的任何事件都需要从 Discord 开发人员门户启用这些意图并在您的代码中进行定义。 Your code is looking fine and should work, until you have enabled intents.您的代码看起来很好并且应该可以工作,直到您启用了意图。 Intents can be enabled from the bot page and should be off by default, for member intents, turn it on.可以从机器人页面启用意图,默认情况下应关闭,对于成员意图,将其打开。

They can be defined within code after you have enabled in the portal:在门户中启用后,可以在代码中定义它们:

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix=',', intents=intents)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM