discord.py-允许作者执行反应

时间:2019-05-22 15:44:10

标签: python python-3.x discord.py

我想让只有执行命令的人才能对反应执行命令,因此当其他人做出反应时,它会影响代码

到目前为止,这里有我的代码

@client.event
async def on_message(message):

    if message.content.lower().startswith("!lol"):
     embed1 =discord.Embed(
        title="Escolha seu Elo!",
        color=COR,
        description="- Bronze = \n"
                    "- Prata  =   \n"
                    "- Ouro  = ",)

    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_user
    msg_user = message.author


@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.find(lambda r: r.name == "Bronze", msg.server.roles)
     await client.add_roles(user, role)
     print("add")

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

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

@client.event
async def on_reaction_remove(reaction, user):
    msg = reaction.message

    if reaction.emoji == "" and msg.id == msg_id: #and user == msg_user:
     role = discord.utils.find(lambda r: r.name == "Bronze", msg.server.roles)
     await client.remove_roles(user, role)
     print("remove")

    if reaction.emoji == "" and msg.id == msg_id: #and user == msg_user:
     role = discord.utils.find(lambda r: r.name == "Prata", msg.server.roles)
     await client.remove_roles(user, role)
     print("remove")

    if reaction.emoji == "" and msg.id == msg_id: #and user == msg_user:
     role = discord.utils.find(lambda r: r.name == "Ouro", msg.server.roles)
     await client.remove_roles(user, role)
     print("remove")

0 个答案:

没有答案