[英]Error give role when a user add reaction 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 Traceback(最近一次通话)中的异常:文件“ C:\\ Users \\ Administrator \\ AppData \\ Local \\ Programs \\ Python \\ Python36-32 \\ lib \\ site-packages \\ discord \\ client.py”,行307,在来自getattr(_event_)的_run_event产量(* args,** kwargs)文件“ C:\\ Users \\ Administrator \\ Desktop \\ project_Bot_manage--Copy-Copy.py”,第24行,位于on_ready client.loop.create_task(on_reaction_add中())TypeError:on_reaction_add()缺少2个必需的位置参数:“ reaction”和“ user”
请我需要帮助,discord.py在这里仍然很新
您需要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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.