问题描述
reaction_remove 不断出现错误,只是复制粘贴了我的整个代码(减去客户端 ID),因为它可能会有所帮助,我不知道有什么问题,因为前半部分工作得很好.
Keep getting an error for the reaction_remove, just copy-pasted my whole code(minus the client id) cause it might help, I have no idea what's wrong as the first half works perfectly fine.
另外,尝试添加"如果成员不是无:等待 member.remove_roles(角色)别的:打印(错误)"最后,每次我尝试删除角色时都会出错,以防万一它有帮助.
Also, trying to add "if member is not None: await member.remove_roles(role) else: Print(error)" at the very end and itgave me errors every time I tried removing roles, just in case it helps.
import discord
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == 806406876593127464:
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == "049":
role = discord.utils.get(guild.roles, name = 'SCP-049')
elif payload.emoji.name == "0492":
role = discord.utils.get(guild.roles, name = 'SCP-049-2')
elif payload.emoji.name == "096":
role = discord.utils.get(guild.roles, name = 'SCP-096')
elif payload.emoji.name == "106":
role = discord.utils.get(guild.roles, name = 'SCP-106')
elif payload.emoji.name == "173":
role = discord.utils.get(guild.roles, name = 'SCP-173')
elif payload.emoji.name == "682":
role = discord.utils.get(guild.roles, name = 'SCP-682')
elif payload.emoji.name == "939":
role = discord.utils.get(guild.roles, name = 'SCP-939')
elif payload.emoji.name == "999":
role = discord.utils.get(guild.roles, name = 'SCP-999')
elif payload.emoji.name == "Chaos":
role = discord.utils.get(guild.roles, name = 'Chaos Insurgency')
elif payload.emoji.name == "DClass":
role = discord.utils.get(guild.roles, name = 'D-Class')
elif payload.emoji.name == "MTF":
role = discord.utils.get(guild.roles, name = 'MTF')
elif payload.emoji.name == "Scientist":
role = discord.utils.get(guild.roles, name = 'Scientist')
member = payload.member
await member.add_roles(role)
@client.event
async def on_raw_reaction_remove(payload):
message_id = payload.message_id
if message_id == 806406876593127464:
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == "049":
role = discord.utils.get(guild.roles, name = 'SCP-049')
elif payload.emoji.name == "0492":
role = discord.utils.get(guild.roles, name = 'SCP-049-2')
elif payload.emoji.name == "096":
role = discord.utils.get(guild.roles, name = 'SCP-096')
elif payload.emoji.name == "106":
role = discord.utils.get(guild.roles, name = 'SCP-106')
elif payload.emoji.name == "173":
role = discord.utils.get(guild.roles, name = 'SCP-173')
elif payload.emoji.name == "682":
role = discord.utils.get(guild.roles, name = 'SCP-682')
elif payload.emoji.name == "939":
role = discord.utils.get(guild.roles, name = 'SCP-939')
elif payload.emoji.name == "999":
role = discord.utils.get(guild.roles, name = 'SCP-999')
elif payload.emoji.name == "Chaos":
role = discord.utils.get(guild.roles, name = 'Chaos Insurgency')
elif payload.emoji.name == "DClass":
role = discord.utils.get(guild.roles, name = 'D-Class')
elif payload.emoji.name == "MTF":
role = discord.utils.get(guild.roles, name = 'MTF')
elif payload.emoji.name == "Scientist":
role = discord.utils.get(guild.roles, name = 'Scientist')
member = payload.member
await member.remove_roles(role)
client.run()
添加反应后可以给我一个角色,但删除该反应后无法删除该角色这里
It was able to give me a role after adding a reaction, but has not been able to remove the role after removing that reaction here
推荐答案
以下答案是使此代码正常工作的解决方案的一部分,因此请实施提供的答案.我在另一个问题中发现,在文档中 payload.member
只有在 event_type
是 REACTION_ADD
时才可用,所以我通过添加来修复它:
The below answer is one part of the solution to make this code work so implement the provided answer. I found out in another issue that in the documentation payload.member
is only available if the event_type
is REACTION_ADD
so i fixed it by adding:
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
添加后,更改
member = payload.member
到
member = guild.get_member(payload.user_id)
这对我有用,如果有帮助,请告诉我.
That is what worked for me let me know if this helps.
这篇关于“NoneType"对象没有属性“remove_roles" Discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!