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

Viewed 298

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")
1 Answers

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.

Related