Solving discord.py AttributeError: ‘Client’ object has no attribute ‘send_message’

discord.py AttributeError: ‘Client’ object has no attribute ‘send_message’ is an error which occurs because of a faulty send method.

This post is my attempt to explain to you why this error occurs and how you can solve it, I will also include multiple solutions that could be considered as alternative fixes to the error.

Explaining the Error : discord.py AttributeError: ‘Client’ object has no attribute ‘send_message’

The error can happen to anyone with a discord bot using a faulty send method.

In order to make sure we are trying to solve the same problem, please verify that your error matches the error message bellow.

                                                                       #
on_message !test
in test function
Ignoring exception in on_message
Traceback (most recent call last):
...
  File "bot.py", line 21, in test
    await client.send_message(message.channel, 'Hi %s, i heard you.' % author)
AttributeError: 'main' object has no attribute 'send_message'
                                                                       #

Bellow you can find the solution which have worked for me plus other popular possible solutions among other python developers who already faced this error.

Solution 1 : use abc.Messageable.send().

The first solution is very simple, make sure your code does respect the new discord API, if you have trouble with messages you should know that Client.send_message(abc.Messageable) has been deprecated and replaced by abc.Messageable.send().

So, the expression bellow.

                                                                       #
await client.send_message(message.channel, 'I recieced the message! {0}'.format(message.author))
                                                                       #

Will be replaced by this line of code.

                                                                       #
await message.channel.send('I recieced the message! {0}'.format(message.author))
                                                                       #

If this solution worked for you, great. If the solution is not enough let us try another one.

Solution 2 : use the commands extension.

The second solution is to use the commands extension in order to create discord bots and create commands for them.

You can replace the code you had before with the code bellow which uses the commands extension.

                                                                       #
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command()
async def test(ctx):
    await ctx.send('I heard you! {0}'.format(ctx.author))
bot.run('token')
                                                                       #

I hope the solutions above have been helpful, I hope you solved the error, you can support us by donating to our Kofi account, this website is free to use but any help is very appreciated and goes a long way.

If the solutions above helped you, consider supporting us on Kofi, any help is appreciated.

Summing-up

The article is over guys, I hope my effort did not go to waste and I helped some of you solve this error, keep learning Python and keep coding, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/