Error: 'Client' Object Lacks send_message Method in Discord Bot

I’ve run into an issue with my Discord bot where it claims that the send_message method is missing from the Client object. I’m receiving an AttributeError each time I attempt to call it. Here’s the updated code I’ve been using:

import asyncio
import discord

bot = discord.Client()

@bot.event
async def on_message(msg):
    user = msg.author
    if msg.content.startswith('!greet'):
        print('!greet command detected')
        await reply_to_user(user, msg)

async def reply_to_user(user, msg):
    print('inside the reply function')
    await bot.send_message(msg.channel, 'Hello %s, I received your message.' % user)

bot.run("your_token")

This is the error message I see:

!greet command detected
inside the reply function
Ignoring exception in on_message
Traceback (most recent call last):
  File "bot.py", line 20, in reply_to_user
    await bot.send_message(msg.channel, 'Hello %s, I received your message.' % user)
AttributeError: 'Client' object has no attribute 'send_message'

Can anyone help me understand what’s going wrong and how to resolve it?

totally get ur frustration! discord.py did change stuff, and that method is gone now. try using await msg.channel.send(‘ur message here’) instead to fix it. should work fine!

You’re mixing API versions. Discord.py removed send_message around version 1.0. Replace await bot.send_message(msg.channel, 'Hello %s, I received your message.' % user) with await msg.channel.send('Hello %s, I received your message.' % user). Way more intuitive - you’re calling send directly on the channel instead of going through the client. Had this exact problem when I updated my bot last year, fixed it instantly. Check your discord.py version with pip show discord.py to make sure you’re not running something ancient.

You’re using old discord.py syntax. The send_message method got deprecated in version 1.0 - they replaced it with something cleaner. Instead of bot.send_message(msg.channel, message), just use msg.channel.send(message) directly. Here’s how your reply_to_user function should look:

async def reply_to_user(user, msg):
    print('inside the reply function')
    await msg.channel.send('Hello %s, I received your message.' % user)

This is way cleaner since you’re calling send directly on the channel object instead of passing it through the client. Also make sure you’re running a recent version of discord.py - the library’s changed a lot over the years.