此外,尝试在最后添加“if member not None:wait member.remove_roles(role)else:Print(error)”,每次尝试删除角色时都会出现错误,以防万一会有所帮助。
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()
它能够在添加反应后给我一个角色,但在这里移除反应后无法移除角色
有效载荷。当事件处于“原始”、“反应”和“移除”状态时,成员将始终为“无”。因此,你必须使用
guild。get_member()
和有效负载的用户id
从缓存中获取成员,这也需要启用成员意图。
下面的答案是解决方案的一部分,可以让代码正常工作,从而实现提供的答案。我在另一期中发现,在文档有效载荷中。成员
仅在事件类型
为反应_添加
时可用,因此我通过添加以下内容对其进行了修复:
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
添加此选项后,请更改
member = payload.member
到
member = guild.get_member(payload.user_id)
这就是我的工作让我知道,如果这有帮助。
如果您尝试打印payload.member
,输出将是无
-这是因为您没有启用intents.members
。使他们能够:
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
还要确保在开发者门户中启用意图
如何启用特权意图
我想在没有命令的情况下为discord编写一条bot消息。但是我在运行代码时遇到了一个问题。错误为:“非类型”对象没有“发送”属性 Traceback(最近的调用最后):文件"D:/Development/Code Python/Bot Discord/discord-testbot.py",第18行,在my_background_task等待channel.send(通道,'New') 属性错误
如果pk_col值为空,则应打印未定义的主键。但我得到了这个错误。“NoneType”对象没有属性“rdd”。
问题内容: 我的程序看起来像 当我运行它时,它会抛出我 不知道为什么会这样?当我已经在每个列表的开头创建列表时 问题答案: 实际上,您存储在此处: 更改列表并返回 例:
问题内容: 下面的代码给出了错误: 码: 问题答案: 从代码中,我可以看到你希望允许用户下载pdf。 现在开始 去 http://localhost:5000
问题内容: 我遇到了这个问题,我不明白为什么。 我从我的应用程序中获取了代码,并制作了此测试代码,因此您不必费劲地查看我的要求。 我有这个工作在其他代码。但是,在将两者进行比较之后,我无法为自己的一生解决这个问题。 在此应用程序中,出现错误“ AttributeError:’NoneType’对象没有属性’delete’”。 问题答案: 在这一行: grid不返回任何内容,因此entryBox是,
我的模型在Slagify系列中有问题 我试着把代码self.slug=slugify(“slug的测试”)放进去,但问题仍然存在,但当他说保留信息时,没有问题 这是我的错误: 环境: 请求方式:POST请求URL:http://xxx.xx.xx.xx:8000/admin/pages/pages/add/ Django版本:1.7.1 Python版本:3.4.2安装的应用程序:('Django