Discord bot, how do I assign a role to the user you mentioned?

Question:

Yes, I did everything through the Client, but I don’t need to enter a command, I just want to conduct a mini-game “zombie”, in which users pinging other users turned them into zombies. To do this, the bot must give a certain role to the person who was pinged by the person in their message. I got the ID of the person you are pinging (maybe this will help). Thanks in advance.

Code is here:

import discord
from discord import utils


client = discord.Client()

@client.event
async def on_ready():
    print('Connected')


@client.event

async def on_message(message):
    if message.author == client.user:
        return
    role = discord.utils.get(message.guild.roles, name='Hot pink') # i get role
    user = message.mentions[0].id #i get id of mention people
  # await .add_roles(mute_role) PROBLEM IS HERE (me need, to give role, to mentioned people)
Asked By: EVASTEFAN

||

Answers:

I can’t understand where this code is from? Is this in your main js file?

Have you tried this?

var role = message.guild.roles.find(role => role.name === "MyRole");
message.member.addRole(role); 
Answered By: Joe Moore
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.