0

The bot commands were working previously and when I run the code I get no errors or any indications of a problem. I am using VS Code. The only thing in the terminal is the on_ready function printing "Bot is ready!"

import discord, random
from discord.ext import commands

bot = commands.Bot(command_prefix = '$')
keywords = ["bike", "tron", "disk"]
keyword_responses = [
    "Greetings, programs!", 
    "**Tron!**", 
    "Now this I can do.", 
    "Behold! The son of our maker!",
    "You'll never make it."]

@bot.event #presence
async def on_ready():
    await bot.change_presence(status = discord.Status.online, activity = discord.Game("Online"))
    print('Bot is ready!')

@bot.event #keyword response
async def on_message(message):
    for i in range(len(keywords)):
        if keywords [i] in message.content:
            for f in range(1):
                await message.channel.send(random.choice(keyword_responses))

#NOT WORKING
@bot.command() #clear command
async def clear(ctx, amount = 3):
    await ctx.channel.purge(limit = amount)
    await ctx.channel.send(f'**{amount} messages have been deleted.**')
#NOT WORKING

#NOT WORKING
@bot.command(name = "quotes") #quotes command
async def quotes(ctx):
    _quotes = [
     "Fortune favors the bold.",
     "Time is money.",
     "If you want to be happy, be.",
     "When life gives you lemons, make lemonade.",
     "Your time is limited, so don't waste it living someone else's life.",
     "The way to get started is to quit talking and begin doing.",
     "Life has a way of moving you past wants and hopes.",
     "You can't steal something that's designed to be given away free.",
     "Out there is a new world! Out there is our victory! Out there is our destiny!",
     "Some things are worth the risk",
     "The art of selflessness... it's about, 'Removing' ones self from the equation",
     "I... fight for the users!"]
    response = random.choice(_quotes)
    await ctx.send(response)
#NOT WORKING

token = "xxx"
bot.run(token)
Jordd
  • 1
  • 3
    Does this answer your question? [Why does on\_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) – Łukasz Kwieciński Jun 21 '21 at 15:32

1 Answers1

1

As @Łukasz Kwieciński already pointed out in his comment:

Overwriting on_message will break the discord.ext.commands Framework. To prevent this, add await bot.process_commands(message) to the end of your on_message function.

Like this:

@bot.event #keyword response
async def on_message(message):
    for i in range(len(keywords)):
        if keywords [i] in message.content:
            for f in range(1):
                await message.channel.send(random.choice(keyword_responses))
    await bot.process_commands(message)
Martin
  • 83
  • 1
  • 7