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

Time:12-26

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

CodePudding user response:

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")

CodePudding user response:

use @client.listen(), I encountered that before and the listen() worked

  • Related