我正在遵循Anson开发人员指南(here's a link),并且完全按照他的编码进行编码,除了警告Parameter 'payload' value is not used
之外,我没有其他错误,并且我已经确保:
此处是供参考的代码:
import discord
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == '756794977148993597':
guild_id = payload.guild_id
guild = discord.utils.find(lambda g: g.id == guild_id, client.guilds)
role = discord.utils.get(guild.roles, name=payload.emoji.name)
if role is not None:
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
if member is not None:
await member.add_roles(role)
print("done")
else:
print("member not found")
else:
print("role not found")
client.run('REDACTED')
我已经尝试了很多故障排除方法,将不胜感激!
答案 0 :(得分:1)
在您的情况下,请勿使用utils.find
。
guild.get_member_named
。@client.event
async def on_raw_reaction_add(payload):
if payload.message_id == 756794977148993597:
guild = client.get_guild(payload.guild_id)
role = discord.utils.get(guild.roles, name=payload.emoji.name)
if role is not None:
member = guild.get_member(payload.user_id)
if member is not None:
await member.add_roles(role)
print("done")
else:
print("member not found")
else:
print("role not found")