py:get_channel()返回NONE [英] dicord.py: get_channel() returns None

查看:16
本文介绍了py:get_channel()返回NONE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个机器人,它除了执行一些代码外,还应该删除添加到特定消息的反应。

在我编写的代码中,方法get_channel()返回None

async def on_raw_reaction_add(self, payload):
    if payload.message_id == self.message_id['private_room']:
        if payload.emoji.name == self.lock:
            rchannel = self.get_channel(payload.channel_id)
            rmsg = await rchannel.fetch_message(payload.message_id)
            ruser = await self.fetch_user(payload.user_id)
            await rmsg.remove_reaction(self.lock, ruser)

我可以使用await fetch_channel()方法,它工作得很好,但由于它是一个API调用,所以它的工作速度比上面提到的要慢得多(至少我认为是这样)。

编辑:

我已尝试使用以下代码进行调试:

print(self.get_user(payload.user_id))
print(await self.fetch_user(payload.user_id))
print(self.get_channel(payload.channel_id))
print(await self.fetch_channel(payload.channel_id))

输出为:

None
wolex#0000
None
lounge

推荐答案

我禁用了membersguilds意图。要启用它们,请执行以下操作:

intents = discord.Intents.none()
intents.reactions = True
intents.members = True
intents.guilds = True
您还需要启用‘’特权网关意图‘’。遵循official docs

这篇关于py:get_channel()返回NONE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆