Since you're expecting the user to send the message in a dm channel, you will need to define the server you'll be adding the role in, as well as what role will be added. Do view the code below, as well as any further explanations.
Edit: My apologies, I had forgotten that you have to get the user from the server itself, otherwise you would (usually) get the error AttributeError: 'User' object has no attribute 'add_roles'
. Also, I had forgotten to await
the add_roles
, which would've given the error 'Member.add_roles' was never awaited
. I would recommend checking or improving your error handler, as it seems to be 'eating up errors'. (Edited code remarks are indicated with ##
, please review the new changes)
if message.guild is None:
# you don't need to do it twice
if passphrase in message.content:
your_guild = bot.get_guild(000000) # put your server's id in here
# check if author is in the guild, if not end the current interaction
if message.author not in your_guild.members: return
## You also need to get the user within the guild
user_from_guild = your_guild.get_member(message.author.id)
verify_role = your_guild.get_role(000000) # put the role id in here
## remember to await add_roles as well!
await user.add_roles(verify_role) # give the author the role
await message.channel.send("You've been verified!")
Other links: