discord.py命令没有响应

时间:2020-08-29 08:28:53

标签: python python-3.x discord.py

代码:

import discord
from discord.ext.commands import Bot
from discord.ext import commands

bot = Bot(command_prefix = ".")


@bot.event
async def on_message(message):
    print(message.content)
    if message.author == bot.user:
       return
    
    if message.content.startswith("hello"):
        await message.channel.send('hello!')



@bot.command(name="lol")
async def _lol(ctx):
    print("lelele")
    print(ctx.author)
    await ctx.send("lelele")
    
  • 当我输入.lol时,Bot没有响应
  • 如果我键入“ hello”,则机器人会回答
  • 问题出在哪里?

1 个答案:

答案 0 :(得分:0)

覆盖提供的默认on_message禁止运行任何其他命令。要解决此问题,请在bot.process_commands(message)的末尾添加on_message行。

import discord
from discord.ext.commands import Bot
from discord.ext import commands

bot = Bot(command_prefix=".")


@bot.event
async def on_message(message):
    print(message.content)
    if message.author == bot.user:
        return

    if message.content.startswith("hello"):
        await message.channel.send('hello!')
        
    await bot.process_commands(message)


@bot.command(name="lol")
async def _lol(ctx):
    print("lelele")
    print(ctx.author)
    await ctx.send("lelele")

Why does on_message make my commands stop working?