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 not responding to @client.event commands

I am not getting a "ping" response with this code. It was working before, but I am not sure what changed. There are no errors on my end, just no response.

Any feedback is appreciated.

import os
import random
import discord
from dotenv import load_dotenv
from discord.ext import commands

load_dotenv()
PREFIX = os.getenv("PREFIX")
TOKEN = os.getenv("TOKEN")
intents = discord.Intents().all()
bot = commands.Bot(command_prefix=PREFIX, intents=intents)


@bot.event
async def on_message(message):
    if message.author == bot.user:  # tells the bot not to respond to itself
        return

@bot.event  # ping-with-latency
async def on_message(message):
    if message.content.startswith(PREFIX + 'ping'):
        await message.channel.send(f'pong! {bot.latency}ms')

@bot.event
async def on_ready():  # display if online/ready
    print("Bot is ready and logged in as {0.user}!".format(bot))

# run bot on server
bot.run(TOKEN)

I have checked all permissions and privileged gateway intents. I know I could be using client.command, but that also doesnt work.

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’re defining two different callbacks for these events – this is probably the problem. Just put the author check in the main on_message.

@bot.event
async def on_message(message):
    if message.author == bot.user:  # tells the bot not to respond to itself
        return

    if message.content.startswith(PREFIX + 'ping'):
        await message.channel.send(f'pong! {bot.latency}ms')
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