Python discord bot doesn't answer to any commands

Question:

The bot starts just fine, but it doesn’t answer to any commands I make with its prefix, it doesn’t even raise the "command not found" exception. The bot was working just fine until some hours ago, I made some changes and it stopped working. I reverted the changes, but it still doesn’t work.

I tried commenting the cogs startup and it still didn’t work, so I think they’re not relevant to the problem. I also left a lot of the code out because it’s pretty big, and I assumed it didn’t matter because the bot is running and if there were any errors in my code, the commands should at least be executed, but let me know if there’s something else I should include.

Here’s the code:

(imports)

(global variables)
bot = commands.Bot(command_prefix='!', help_command=None, case_insensitive=True, 
intents=discord.Intents.default())

@bot.event
async def on_ready():
  (cogs setup)
  await bot.change_presence(activity=discord.Game(name='random status'))
  print("My prefix is: " + bot.command_prefix)
  print('We have logged in as {0.user}'.format(bot))

@bot.command()
async def random_command(ctx):
  print("Command executed)


def random_method():
  (does something)


bot.run(token)

The "on_ready" event is executed just fine, and the bot comes online in discord. I don’t have any on_message events and the bot has admin perms in my server.

Asked By: Carlos

||

Answers:

To improve privacy bots now need a special intent in order to be able to read messages. The "new" commands (which i would recommend you to switch to) are slash commands as they are fully supported by Discord. You can find more information on how to set up slash commands here.

If you want to stick with the old method, here is he to activate the intent: First go to your Developer Portal, select your application and activate the Message Content Intent. Next you need to activate the intent in your code like this:

intents = discord.Intents.default()
intents.messages = True
bot = commands.Bot(command_prefix='!', help_command=None, case_insensitive=True, intents=intents)

Note that if your bot is on 100 or more servers it needs to be verified in order to access intents. More information on that can be found here.

Answered By: DwarfDev
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.