I've seen this issue posted here multiple times and it is usually said to be an issue of the code but there is one from 10 days ago that seemed to not have an answer yet, so I'm thinking there still may be an issue in the code here?
Doing:
mgs = []
async for x in client.logs_from(client.get_channel('361683030932193281')):
mgs.append(x)
await client.delete_messages(mgs)
Getting "'NoneType' object has no attribute 'id'"...
Tried doing it a multitude of different ways including having the get_channel code as it's own line with a name and whatnot.
Traceback: https://i.imgur.com/z4ptQt3.png
Didn't you just ask that in the server
And we answered you
I'm not in any server or asking questions elsewhere. If you have that many people asking the same question, perhaps it's time to update the docs or make the code more clear. That's actually kind of funny and really reinforces my point of a bunch of people asking the same question.
Oh then sorry (Wow what a world), is that a channel, are you calling that before the bot has started?
'361683030932193281' isn't valid channel id and it returned None
^
The bot should be in the server. I'm converting it from being triggered by a message, to a background task being triggered on a timed basis. So I'm replacing (trying to, at least...) all the message.channel instances with an actual pre-defined channel ID.
I got that channel ID from both back-slashing the channel name, as well as hitting "Copy ID" by right-clicking the channel name.
get_channel returns None when a channel with the specified channel ID was not found in the cache.
This raises some possibilities:
wait_until_ready, which sleeps the coroutine until all channels, guilds and members are available in cache.Judging by your last comment, I'm going to guess it's the first one. Stick a
await client.wait_until_ready()
before your main code and see if it fixes the problem.
That fixed it. (wait_until_ready(), not the rest) Thanks, Gorialis. Great answer.
That fixed it. (wait_until_ready(), not the rest) Thanks, Gorialis. Great answer.
could u explain how to add this
Most helpful comment
get_channelreturns None when a channel with the specified channel ID was not found in the cache.This raises some possibilities:
wait_until_ready, which sleeps the coroutine until all channels, guilds and members are available in cache.Judging by your last comment, I'm going to guess it's the first one. Stick a
before your main code and see if it fixes the problem.