Discord bot not reacting to commands

This is my code:

import os
my_secret = os.environ[‘TOKEN’]
import discord

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
print(f’We have logged in as {client.user}')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!GamedleHelp'):
    await message.channel.send('''**Los comandos actuales**
    
    Gamedle Clasico: !GamedleClassic
    Gamedle Arte: !GamedleArtwork
    Gamedle Adivinanza:!GamedleRiddle
    Gamedle Palabras Clave: !GamedleKeyWords''')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!GamedleClassic'):
    await message.channel.send('Time Crisis II')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!GamedleArtwork'):
    await message.channel.send('Uncharted: The Lost Legacy')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!GamedleRiddle'):
    await message.channel.send('Harry Potter and the Goblet of Fire')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!GamedleKeyWords'):
    await message.channel.send('The Elder Scrolls V: Skyrim')

client.run(my_secret)

It’s a discord bot, it starts and everything but not when I put a command he doesn’t respond. I would like a solution.

Change intents to discord.Intents.all()… I also suggest you don’t use message.content.startswith to check if something is a command, and instead use @commands.Command()
I made a template for this a while back that should still be working if you want to try it: https://replit.com/@InvisibleOne/Working-Discordpy-Template

3 Likes

Also if you want to use slash commands you can do so like this, but they are a bit more complicated to use:

import discord
import asyncio
from discord import app_commands
import os

intents = discord.Intents.all()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)

ID = 10237408734809 # that's just some random numbers but it should look something like that


@tree.command(name="hello", description="say hello", guild=discord.Object(id=ID))
async def hello(interaction):
    await interaction.response.send_message("Hello!")

@client.event
async def on_ready():
    await tree.sync(guild=discord.Object(id=ID))
    print("Ready!")

def main():
	client.run(os.environ["TOKEN"])



asyncio.run(main())
4 Likes

Oh and again… I’m an idiot, the real reason it’s probably not working is because you recreated the on_message event a bunch of times, you only do it once and then just use if to check what the message is…

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith("!hi"):
       await message.channel.send("hello")
    elif message.content.startswith("!ping"):
       await message.channel.send("pong")
4 Likes

Your help was helpful. Thank you

1 Like

That’s great news @soggygamer22 , if @InvisibleOne has helped you solve your issue please mark one of their posts as the solution as this can help others in the community in the future.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.