Search code examples
pythonpython-3.xdiscorddiscord.py

dicord.py: get_channel() returns None


I am working on a bot which in addition to executing some code should remove reactions added to a specific message.

In the code I wrote, the method get_channel() returns 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)

I can use await fetch_channel() method which works fine but as it's an API call it's working much slower (at least I think it is) than the one mentioned above.

EDIT:

I've tried to debug with the following code:

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))

The output is:

None
wolex#0000
None
lounge

Solution

  • I had members and guilds intents disabled. To enable them do the following:

    intents = discord.Intents.none()
    intents.reactions = True
    intents.members = True
    intents.guilds = True
    

    You'll also need ''Privileged Gateway Intents'' enabled. Follow the official docs.