Skip to content Skip to sidebar Skip to footer

AttributeError: 'NoneType' Object Has No Attribute 'send' Discord.py Rewrite

I'm trying to send a message to a specific channel. I have still not been able to figure out how to do this. Help is greatly appreciated. import keep_alive import discord client =

Solution 1:

get_channel won't work where you have it because the bot hasn't connected to discord yet (that happens during run). When the bot connects, it will build internal caches of all the things it's aware of (members, guilds, channels, etc.). Those caches are what the various get methods use, but since the caches are empty those methods return None.

Instead, you can either get the channel in the on_message every time, or use a global variable in the on_ready:

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('$hello'):
        channel = client.get_channel(1234)
        await channel.send('hello')

Post a Comment for "AttributeError: 'NoneType' Object Has No Attribute 'send' Discord.py Rewrite"