Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord.py on_message: nothin happens when i type the message

import discord

from discord.ext import commands

TOKEN = 'XXXXX'
prefix = "!"
client = discord.Client()

    
@client.event
async def on_message(message):
  if message.content == prefix + "hey":
     await client.reply("hello there")

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

client.run(TOKEN)

in the first @client.event when i use the command given there prefix + "hey", nothing happens. it doesnt give the desired reply

AttributeError: ‘Client’ object has no attribute ‘reply’

thats the error i get

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to use message.reply instead of client.reply.

Note that is better to create commands using special discord.py decorator:

from discord.ext import commands


bot = commands.Bot(command_prefix="!")


@bot.command()
async def hey(ctx):
    ctx.reply("Hello there!")

bot.run("TOKEN")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading