Nekidev
Nekidev

Reputation: 77

discord.py @bot.command() not running

I've got something like this.

from flask import Flask
from threading import Thread
import discord
from discord.ext import commands, tasks
from discord.utils import get
import requests
from Moderator.badwords import words
import time
import datetime
from Stats.uptime import data

help_command = commands.DefaultHelpCommand(
    no_category = 'Commands'
)

intents = discord.Intents().all()
bot = commands.Bot(command_prefix='!', description="Hey there, I'm Botty (for example)!", help_command=help_command, intents=intents)

@bot.command()
async def hello(ctx):
  await ctx.send(ctx.author.mention + " hello!")

@bot.event
async def on_ready():
  print('Ready!')

@bot.event
async def on_message(message):
    for word in words:
        if word in message.content.lower():
            await message.delete()
            await message.channel.send("Oops! Seems like " + message.author.mention + " was trying to send a message that was breaking the " + bot.get_channel(783064049859559434).mention + ". Luckily, I deleted it before it caused any more damage. Don't send any more messages like that!\n\nIf you think that I made an error, please report it in " + bot.get_channel(783074030265040916).mention + ", " + bot.get_channel(783074002255478848).mention + " or in " + bot.get_channel(783092164590174251).mention)

@bot.event
async def on_member_join(member):
  print(f"{member} joined the server")

bot.run(TOKEN)

Now, I can compile and run this code with no errors, and when a member joins or a user sends a message, all works perfectly fine. But when it comes to run commands, it does not even start. Is there something i'm missing?

Thanks in advance

Upvotes: 0

Views: 16495

Answers (2)

Itay Dumay
Itay Dumay

Reputation: 139

It seems that this code is perfectly fine, did you define the prefix correctly? To define the prefix you need to import commands from discord.ext Your bot should look like this:

from discord.ext import commands
import discord
TOKEN = ...
bot = commands.Bot(command_prefix=".")
#####
async functions
#####
bot.run(TOKEN)

Upvotes: 0

Wha-
Wha-

Reputation: 254

The documentation:

Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message.

If you override an on_message, you need to use await bot.process_commands(message) so that the commands are processed. Try adding that to your on_message event.

Upvotes: 16

Related Questions