Replit Discord.py bot: commands do nothing?

Hello,

I followed Beau’s Youtube tutorial for making a Replit Discord Bot using python, it was great. It’s working and integrated with UptimeRobot. Here is my bot: https://replit.com/@drewshields/EducatedTechnoSpellchecker

I previously had a Discord bot I wrote in Visual Studio Code and used several commands which worked great. However, when I try to use the Discord.py commands in Repl.it, they do nothing. I don’t get a traceback error or any feedback. The bot just won’t respond. Commands as simple as:

@client.command()
async def test(ctx):
await ctx.send (“Hello”)

Can anyone suggest anything I might try? Like I said, I know the commands work with the discord.py API because I’ve run them with other programs.
Thanks,
-Drew

@drewshields Welcome to the forum.

I am not familiar with discord or bots but I would say is that when Python does not do anything is when no function is being called OR you need to wrap the function in a print() statement to see output.

I had a look at the bot’s code. I think the issue here is the on_message listener.
Generally on any message sent, this first event triggered, and thus this over-rides the commands-processing.

@client.event
async def on_message(message):
  if message.author == client.user:
    return
  msg = message.content
  if msg.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)

This can be resolved by either of the following methods-

  • Call commands.ext.Bot.process_commands(message) to run the commands processing on the message. The fix in your code would be like this-
    @client.event
    async def on_message(message):
      if message.author == client.user:
        return
      msg = message.content
      if msg.startswith('$inspire'):
        quote = get_quote()
        await message.channel.send(quote)
    
      # process commands
      await client.process_commands(message)
    
    and Yaay, that should fix it :slight_smile:
    OR
  • Split the bot up into cogs and put the listener in it’s own cogs. If you are unfamiliar with the use of cogs, I suggest that you keep this method in mind for future, and use this later.
1 Like

I tried this single line of code change, it worked like a dream. At least for the single test command that I tried. But I think this is my solution.

I was ready to write this project off, thank you so much. I am pretty new so this aid is really special.

1 Like

I have almost the same code as OP and whenever I try to use “await client.process_commands(message)” I get the error: “AttributeError: ‘NoneType’ object has no attribute ‘id’”

I had the same issue as Drew. Using this code made the command work but do I have to use this code for every command?