Discord.py: 'NoneType' object has no attribute 'id'

Created on 7 Oct 2017  路  9Comments  路  Source: Rapptz/discord.py

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

invalid

Most helpful comment

get_channel returns None when a channel with the specified channel ID was not found in the cache.
This raises some possibilities:

  • The channel is not in cache yet. Try using wait_until_ready, which sleeps the coroutine until all channels, guilds and members are available in cache.
  • This channel doesn't exist (you copied the ID wrong or similar)
  • The bot logged in can't actually see the channel (this doesn't mean that it can't read from it and should only happen when not in a mutual guild)

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.

All 9 comments

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:

  • The channel is not in cache yet. Try using wait_until_ready, which sleeps the coroutine until all channels, guilds and members are available in cache.
  • This channel doesn't exist (you copied the ID wrong or similar)
  • The bot logged in can't actually see the channel (this doesn't mean that it can't read from it and should only happen when not in a mutual guild)

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shea4 picture Shea4  路  21Comments

ThePiGuy24 picture ThePiGuy24  路  17Comments

downloadpizza picture downloadpizza  路  14Comments

rektile picture rektile  路  18Comments

imayhaveborkedit picture imayhaveborkedit  路  58Comments