MM4760
MM4760

Reputation: 73

How can I make a bot that listens for events but also has commands in discord?

I need my discord bot to listen for events and I need it to have commands. Here is an example of my problem

import os
from keepalive import keep_alive
from discord.ext import commands

client = commands.Bot(command_prefix = "$")

banned_words = [
"blah", "blahh", "blahhh"
]

@client.event
async def on_message(message):

    msg = message.content
    msgsend = message.channel.send

    if any(word in msg.lower() for word in banned_words):
        await message.channel.purge(limit=1)
        await msgsend("Please don't use banned words!")

@client.command()
async def dice(message, amount:int):
    await message.channel.send("blah blah blah")

Upvotes: 4

Views: 707

Answers (1)

Ratery
Ratery

Reputation: 2917

Add await client.process_commands(message) at the beggining of your on_message event. This code process commands and allow users to invoke/use them.

Upvotes: 3

Related Questions