【发布时间】:2019-05-31 18:22:41
【问题描述】:
但对我不起作用..,
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")
- \U0001F3D3 = :ping_pong: ,使用 unicode
所以它工作,但给了我一些错误
忽略 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 - Copy.py”,第 24 行,在 on_ready client.loop.create_task(on_reaction_add()) TypeError: on_reaction_add() 缺少 2 个必需的位置参数:'reaction' 和 'user'
我需要帮助,我还是 discord.py 的新手
【问题讨论】:
-
我也试过了,但没用:stackoverflow.com/questions/52210855/…
-
这条线应该做什么
client.loop.create_task(on_reaction_add())?你不需要那条线 -
@PatrickHaugh 好的,我删除了那行,(没有问题显示+没有给我这个角色。)
-
reaction.message.channel.id != Channel您应该比较两个Channel对象,而不是带有字符串的Channel对象。试试reaction.message.channel != Channel -
@PatrickHaugh 成功了,谢谢,你能把它发布为“回答问题”吗,请你添加一会儿我删除我的反应会删除我的角色,我试过如果反应.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) else: await bot.remove_roles(reaction.message.author,Role) if 在reaction.message.author.roles 中的角色:await client.remove_roles(reaction.message.author,Role) else:await client.add_roles(reaction.message.author,Role )
标签: python python-3.x discord discord.py