F
F
FeeFort2020-12-13 15:42:25
Python
FeeFort, 2020-12-13 15:42:25

Why did the bot suddenly stop getting channel id in discord.py?

Hello. There is a code for getting a channel ID and sending a message:

channel = bot.get_channel(787656357670420500)
await channel.send(embed=embed1)

It worked and everything was fine. But after a couple of minutes, he came up with this:
AttributeError: 'NoneType' object has no attribute 'send'

As far as I understand, he cannot get the channel ID. But why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Amoralny, 2020-12-13
@FeeFort

You may be trying to get a channel when the bot has not yet connected to the Discord system, as a result, the bot is trying to fetch the channel from the cache.
Correctly

class MyBot(commands.Bot):
    async def on_ready(self):
        channel = self.get_channel(787656357670420500)

Wrong!
class MyBot(commands.Bot):
    def __init__(self):
        channel = self.get_channel(787656357670420500)

!!! The channel ID must be a number, not a string!

ps. info from here, google more often

https://github.com/Rapptz/discord.py/issues/2409

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question