discord.py-添加角色问题

时间:2019-05-23 06:57:43

标签: python discord.py

我试图制作一个反应菜单来赋予角色,到目前为止,它仍然可以正常工作,但是问题是当我执行命令!lol @[person here]并对其做出反应时,它会将角色添加到作者(me)中,不是我提到的用户,请帮助

我的代码是

import discord
#import secreto
import asyncio
from discord.utils import get
from discord.ext import commands

client = commands.Bot(command_prefix='!')

COR =0x690FC3
msg_id = None
msg_user = None

@client.event
async def on_ready():
    print('BOT ONLINE!')
    print(client.user.name)
    print(client.user.id)

@client.command(pass_context=True)
async def lol(ctx, user = discord.Member):
        message = ctx.message
        embed1 =discord.Embed(title=f"Choose {user.name}'s rank", color=COR, description=" - Pineapple\n - Apple\n - Watermellon")
        botmsg = await client.send_message(message.channel, embed=embed1)
        await client.add_reaction(botmsg, "")
        await client.add_reaction(botmsg, "")
        await client.add_reaction(botmsg, "")
        global msg_id
        msg_id = botmsg.id

        global msg_author
        msg_author = message.author

        global msg_user
        msg_user = user

@client.event
async def on_reaction_add(reaction, user):
    msg = reaction.message
    if reaction.emoji == "" and msg.id == msg_id: # and user == msg_user:
        role = discord.utils.get(user.server.roles, name="Bronze")
        await client.add_roles(user, role)
        print("add" + user.name)

    if reaction.emoji == "" and msg.id == msg_id:
        role = discord.utils.get(user.server.roles, name="Prata")
        await client.add_roles(user, role)
        print("add")

    if reaction.emoji == "" and msg.id == msg_id:
        role = discord.utils.get(user.server.roles, name="Ouro")
        await client.add_roles(user, role)
        print("add")

1 个答案:

答案 0 :(得分:0)

user中的

on_reaction_add(reaction, user)始终是对邮件做出反应的用户。您需要mentioned_user = message.mentions[0]来吸引消息中提到的用户,并给他相应的角色。