A
A
Andrew2021-02-02 15:39:22
Python
Andrew, 2021-02-02 15:39:22

'NoneType' object has no attribute 'send' What to do?

There is a code (error output to a specific chat):

@commands.Cog.listener()
    async def on_command_error(self, ctx,  exception): 
        embed = discord.Embed(title=':x: Command Error', colour=0xe74c3c)  # Red
        embed.add_field(name='Command', value=ctx.command)
        embed.description = f"```py\n{traceback.format_exception(type(exception), exception, exception.__traceback__)}\n```"
        embed.timestamp = datetime.datetime.utcnow()
        channel = self.client.get_channel(727801516626542634)
        await channel.send(embed=embed)

    @commands.Cog.listener()
    async def on_error(self, event):
        embed = discord.Embed(title=':x: Event Error', colour=0xe74c3c)  # Red
        embed.add_field(name='Event', value=event)
        embed.description = f"```py\n{traceback.format_exc()}\n```"
        embed.timestamp = datetime.datetime.utcnow()
        channel = self.client.get_channel(727801516626542634)
        await channel.send(embed=embed)


Gives an error:
await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'
Tell me why there is no attribute?...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zexer, 2021-02-02
@Mikyc

Because channel is of type None because the get_channel method returned that value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question