我正在使用 discord.py 库为我的 Discord 服务器创建一个机器人。目前我正在尝试处理当用户从消息中删除他们的反应时会发生什么。我已将 Discord 更新到最新版本,允许使用 Developer Portal 和通过如下代码进行意图:
procedure TfMyClass.DPaint1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if (Shift = [ssctrl]) and (key = VK_DELETE) then
//Going to delete graphically and from database
if (Shift = []) and (key = VK_DELETE) then
//Going to delete just Graphically
end;
这是 on_raw_reaction_remove 函数的代码:
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=('$', '?'), intents=intents)
以及一旦消除反应就会产生的错误:
channel = 867854256647176252
message = 867855236861132860
if payload.channel_id == channel and payload.message_id == message:
guild = bot.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
emoji = payload.emoji
global channels
channels = str(channels)
channels = channels.split()
if str(emoji.name) == '?' :
role = discord.utils.get(guild.roles, name='Offtopic')
for index in range(len(channels) - 1, -1, -1):
if channels[index] == 'Offtopic':
channels.pop(index)
await payload.member.remove_roles(role)
类似问题的答案都无法帮助解决这种情况,任何帮助表示赞赏。
答案 0 :(得分:1)
NoneType 表示您正在访问的值 (payload.member
) 设置为 None,因此没有 remove_roles()
函数。您将上面的 member 定义为它自己的独立变量,所以您打算改为使用 member.remove_roles()
吗?