Reputation: 11
My commands don't work and I think it's because of the on_message
event. When it checks if message is in the good channel, it actually "steel" the command so my bot commands are not triggered but I don't know how to fix that
import discord, os
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='.',intents=intents)
defrole = ""
cmdchannels = ["none"]
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
await bot.change_presence(activity=discord.Game('.help'))
@bot.event
async def on_member_join(member):
await member.add_roles(discord.utils.get(member.guild.roles, name=defrole))
@bot.event
async def on_message(message):
if message.channel.id in cmdchannels :
await message.delete()
@bot.command()
async def setcmd(ctx, arg):
global cmdchannels
cmdchannels.append(discord.utils.get(ctx.guild.channels, name=arg).id)
print(cmdchannels)
await ctx.send(arg+' is now defined as a cmd/bot channel !')
@bot.command()
async def defaultrole(ctx):
global defrole
defrole = str(ctx.message.role_mentions[0])
await ctx.send(defrole+' is now the default on join role !')
bot.run("Token")
Upvotes: 0
Views: 177
Reputation: 4743
on_message
event blocks your commands from working. In order to prevent this, you have to process commands.
@bot.event
async def on_message(message):
if message.channel.id in cmdchannels :
await message.delete()
await bot.process_commands(message)
Upvotes: 0
Reputation: 1427
You will need to process the commands, add this line at the end of your on_message
function:
await bot.process_commands(message)
Reference: process_commands()
Upvotes: 2