SwiftCoding
SwiftCoding

Reputation: 45

Discord.py on_message isnt a @bot.event?

import datetime
import discord
from discord import message, ActivityType
from discord.ext import commands
import asyncio

intents = discord.Intents().all()
bot = commands.Bot(command_prefix='.', intents=intents)
guild = 'SwiftNetwork'
time = datetime.date.today()
badword = ['bw', 'bw1', 'bw2', 'bw3']


@bot.event
async def on_ready():
    print('Wir sind als {1} auf {0} eingeloggt Vers: {2}'.format(guild, bot.user.name, discord.__version__))
    channel = bot.get_channel(id=697572461629407305)
    await channel.send('Heute ist der {0}.{1}.{2}'.format(time.day, time.month, time.year))
    # await bot.channel.send('Beep Boop Beep, Roboter Angriff wird gestartet..')
    bot.loop.create_task(status_task())


@bot.command()
async def hello(ctx):
    await ctx.channel.send(f"Hello! {ctx.author.mention}")


@bot.command()
async def ping(ctx):
    await ctx.channel.send(round(bot.latency * 1000))


@bot.command()
async def poll(ctx, message, *args):
    # print(len(args) + 1)
    emoji = '1️⃣'
    pollem = discord.Embed(title='', description=f'{message}')
    context = []

    reactionx = ['1️⃣', '2️⃣', '3️⃣', '4️⃣']

    if len(args) >= 2:

        for r in range(0, len(args), 2):
            reaction = ['1️⃣', '2️⃣', '3️⃣', '4️⃣']

        for x in range(1, len(args), 2):
            context.append(args[x])

        for a in range(0, len(args), 2):
            pollem.add_field(name=' {1} {0}'.format(args[a], reaction[int(r / 2)]), value=context[int(a / 2)],
                             inline=False)

        ms = await ctx.channel.send(embed=pollem)

    else:
        await ctx.channel.send('Check Args')


async def status_task():
    async def status_task():
        while True:
            await bot.change_presence(activity=discord.Game('Hello'), status=discord.Status.online)
            await asyncio.sleep(3)
            await bot.change_presence(activity=discord.Game('Moin'), status=discord.Status.online)
            await asyncio.sleep(3)
            await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"), status=discord.Status.online)
            await asyncio.sleep(3)


@bot.event
async def on_message(ctx):
    if ctx.author.bot:
        return
    for word in ctx.content.split(' '):
        if word in badword:
            await ctx.delete()


The problem is in the last event. If I run it like this, the ctx.delete() will work but all the commands above won't. If I remove the @bot.event, the commands work, but the ctx.delete() won't.

I'd like to say I'm sure it's cause of the @bot.event, but in on_ready I'm using it as well and it works fine. So right now I really don't see any issues in the code.

Upvotes: 0

Views: 387

Answers (1)

Nurqm
Nurqm

Reputation: 4743

When you're using on_message event, it will block other commands from working. For fixing that, you need to use await bot.process_commands(message). You need to add it end of your on_message event code.

For more information about bot.process_commands, you can look at the API references.

Upvotes: 2

Related Questions