Max '
Max '

Reputation: 11

I can't run any command discord.py

So I've been creating a bot for discord so I've been following many tutorials but my only command won't run. So here is my code :

import discord
import os
from discord.ext import commands

client = discord.Client()
bot = commands.Bot(command_prefix = "_")

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith("salut le bot"):
        await message.channel.send("Salut, je suis Bapo Bot, pour vous servir !")
    if message.content.startswith("merci fréro"):
        await message.channel.send("De rien mon gars !")
    if str(message.channel) == "uniquement-des-images" and message.content != "":
        await message.channel.purge(limit=1)
        print('Message :', (message.content), 'from', (message.author), 'deleted successfully.')

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print(discord.__version__)
    print('------------------')

@bot.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run(os.environ['BOT_TOKEN'])

This code does not give any errors. At first I thought the client = discord.Client() was creating the error but when I deleted it the entire bot didn't work anymore. I tried changing the bot prefix or changing the name of the thing that is now called bot (I'm still a noob in python so I don't what this thing is called) and now I'm stuck.

Edit : As the answer has been deleted by a moderator (?) here is the solution. You can't use a on_message function at the same time as a command function.

Upvotes: 1

Views: 483

Answers (1)

rzk3
rzk3

Reputation: 203

You need to add await client.process_commands() to your on_message event!

I personally leave mine at the bottom of the method!

Upvotes: 2

Related Questions