'clear command just doesn't work discord.py 2.0
i have been fiddiling with this for the last 2 hours and don't understand why it doesnt work, i have message intents enabled, i have establisbed the commands properly, i am using the right prefix and amount. I've looked over my code multiple times but still do not see or understand why nothing happens, literally nothing happens lol.
from dis import dis
from importlib.metadata import requires
from sys import prefix
from unicodedata import name
from click import command, pass_context
import discord
from discord.ext import commands
import json
import requests
import asyncio
with open('badwords.json', 'r') as f:
data = json.load(f)
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
print(discord.__version__)
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'{bot.user.name} is Online!')
@bot.event
async def on_message(msg):
if msg.author != bot.user:
for text in data['words']:
if text in msg.content or text.upper() in msg.content or text.capitalize() in msg.content:
await msg.delete()
return
@bot.command()
@commands.has_permissions(manage_messages=True)
async def purge(ctx, limit: int):
await ctx.message.delete()
await asyncio.sleep(1)
await ctx.channel.purge(limit=limit)
Solution 1:[1]
In general terms, your 'on_message' event is blocking all other commands from running.
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. For example:
async def on_message(message): # do some extra stuff here await bot.process_commands(message)
The default on_message contains a call to this coroutine, but when you override it with your own on_message, you need to call it yourself.
Edit: In regards to your comment, I assume that you added the 'process_commands' in the wrong place. If I'm not mistaken, then your code should look something like this:
@bot.event
async def on_message(msg):
if msg.author != bot.user:
for text in data['words']:
if text in msg.content or text.upper() in msg.content or text.capitalize() in msg.content:
await msg.delete()
return
await bot.process_commands(message)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
