用户添加反应Discord.py时出错赋予角色

时间:2019-01-05 11:21:32

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

但对我没用..

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game
import math, time
from discord.ext import commands
from discord.utils import get


 Client = discord.client
 client = commands.Bot(command_prefix = '!')
 Clientdiscord = discord.Client()


@client.event
 async def on_ready():

 Channel = client.get_channel('524415641310986252')
 Text= "testt!"
 Moji = await client.send_message(Channel, Text)
 await client.add_reaction(Moji, emoji='\U0001F3D3')

 client.loop.create_task(on_reaction_add())

@client.event
 async def on_reaction_add(reaction, user):
Channel = client.get_channel('524415641310986252')
if reaction.message.channel.id != Channel:
 return
if reaction.emoji == "\U0001F3D3":
  Role = discord.utils.get(user.server.roles, name="verified")
  await client.add_roles(user, Role)
  await client.add_roles(reaction.message.author, role)

client.run("My_Token")
  

忽略on_ready中的异常   追溯(最近一次通话):     _run_event中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ discord \ client.py”,第307行       从getattr(self,event)(* args,** kwargs)的收益     文件“ C:\ Users \ Administrator \ Desktop \ project_Bot_manage--复制-Copy.py”,第24行,在on_ready中       client.loop.create_task(on_reaction_add())   TypeError:on_reaction_add()缺少2个必需的位置参数:'reaction'和'user'

请帮助我,我仍然不熟悉discord.py

1 个答案:

答案 0 :(得分:0)

您需要一个on_reaction_remove事件来在用户删除其反应时删除该角色:

msg = None
tennis = "\N{TABLE TENNIS PADDLE AND BALL}"

@client.event
async def on_ready():
    channel = client.get_channel('524415641310986252')
    global msg
    msg = await client.send_message(channel, "React to me!")
    await client.add_reaction(msg, tennis)

@client.event
async def on_reaction_add(reaction, user):
    if reaction.user == client.user:
        return
    if reaction.message == msg and reaction.emoji == tennis:
        verified = discord.utils.get(user.server.roles, name="verified")
        await client.add_roles(user, verified)

@client.event
async def on_reaction_remove(reaction, user):
    if reaction.message == msg and reaction.emoji == tennis:
        verified = discord.utils.get(user.server.roles, name="verified")
        await client.remove_roles(user, verified)