0

i'm making a discord bot with python. I have some issues about running using @client.command and @client.event at the same time. Here is the code: when I comment the @client.event before the on message function, the join command run. This function cause a particular issue, do you know guys where it can come from? Thank you guys

import discord
import random
from discord.utils import get
from discord.ext import commands
@client.command(pass_context=True)
async def join(ctx):
  channel = ctx.author.voice.channel
  await channel.connect()
@client.command(pass_context=True)
async def leave(ctx):
    await ctx.voice_client.disconnect()
@client.event
async def on_ready():
  print("We have logged as {0.user}".format(client))
@client.event
async def on_message(message):
  user = message.author.id
  if message.content.lower() == "!poisson":
    await message.delete()
    with open('myimage.png', 'rb') as f:
      picture = discord.File(f)
      await message.channel.send(file=picture)
Arbaks
  • 1
  • 4
    Does this answer your question? [Why does on\_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) – dotmashrc Feb 07 '22 at 20:15

1 Answers1

-1

Put await client.process_commands(message) at the end of on_message() If you're using on_message, then normal commands will be overridden unless you use process_commands.

Trent112232
  • 169
  • 8
  • 2
    Please don't post answers if it's a duplicated question – LoahL Feb 07 '22 at 20:50
  • Hey Trent, it shows the following error client.process_commands(message) RuntimeWarning: Enable tracemalloc to get the object allocation traceback – Arbaks Feb 08 '22 at 18:13
  • @Arbaks I forgot to mention, but you should use await. My bad, edited the answer accordingly – Trent112232 Feb 08 '22 at 21:22