- You can only add roles to
discord.Member
instances, when defining the member variable you're getting the ID itself, not the discord.Member
instance
member = message.author # Without the id attribute
- In
Member.add_roles
you need to pass discord.Role
instances, not the ID's itself, you can get the instance with Guild.get_role
role = message.guild.get_role(role_id)
await member.add_roles(role)
Your code fixed:
async def on_message(message):
member = message.author
if message.content.startswith("/verify"):
role = message.guild.get_role(ROLE_ID_HERE)
await member.add_roles(role)
There's another issue, you need to enable intents.members
and a few more intents, otherwise some attributes can be a NoneType
intents = discord.Intents.default()
intents.members = True # Explicitly enabling members as it's a privileged intent
client = discord.Client(intents=intents)
Also remember to enable privileged member intents in the developer portal, guide
Reference:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…