简体   繁体   中英

Discord.py bot.command stopped working after usage of on_message

I have a script with both bot.command and bot.event but for some reason only bot.command is working

bot.command and bot.event work separately but not together for some reason

Here is the code:

# bot.py
import discord
from discord.ext import commands
from discord.utils import get

TOKEN = ('token')
bot = commands.Bot(command_prefix=',')



@bot.event

async def on_ready():
    print(f'{bot.user} has connected to Discord!')


@bot.event
async def on_message(message):
    if foo:
        await message.channel.send("foo")


@bot.command(pass_context=True)
async def foo(ctx, args):
    foo = bot.get_user(args)
    await ctx.send(foo)








bot.run(TOKEN)

Thanks

In on_message you need to process your bot's commands:

await bot.process_commands(message)

Also you do not need to use pass_context=True anymore, it is always passed now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM