Discord Bot Command Ignored?

Question:

I started to work on building a Discord Bot using Python and I can’t for the life of me figure out why it is not reacting to commands. I have googled and read various questions on here about DMing users and all I’ve found are what looks to be conflicting answers. I have looked at YouTube videos and copied code for code.

I have tried to set up DMing a user, a role and even just a simple command like ping and pong. Nothing. I have set Intents both in the code and in Developer Tools to All/On and still nothing.

I have an event setup that when a certain word is said the bot responds with a random.choice of a list which is working fine.

import nest_asyncio
nest_asyncio.apply()

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

import random
import os


load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')

intents = discord.Intents.default()

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

@bot.event
async def on_ready():
    guild = discord.utils.find(lambda g: g.name == GUILD, bot.guilds)
    print(
        f'{bot.user} is connected to the following guild:n'
        f'{guild.name}(id: {guild.id})'
    )

@bot.command
async def ping(ctx):
        await ctx.send('pong')
Asked By: sssnow

||

Answers:

To anyone else who finds this as I did see others across my browsing have similar issues:

1
Make sure the @client/bot.command have () at the end of them.

2
There are guides on discord bot building with python however whilst helpful it does appear most are somewhat out of date to newer versions of Python/Discord.py.

Answered By: sssnow
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.