Discord bot,我如何为您提到的用户分配角色?

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

是的,我都是通过客户端做的,但是我不需要输入命令,我只是想进行一个小游戏"zombie",其中用户ping其他用户将他们变成僵尸.要做到这一点,机器人必须在他们的消息中为被 ping 的人赋予特定的角色。我得到了你正在 ping 的人的 ID(也许这会有所帮助)。提前致谢。

代码在这里:

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)

我不明白这段代码是从哪里来的?这是在您的主 js 文件中吗?

你试过吗?

var 角色 = message.guild.roles.find(角色 => role.name === "MyRole"); message.member.addRole(角色);