【问题标题】:discord.py command not respondingdiscord.py 命令没有响应
【发布时间】:2020-11-13 21:44:51
【问题描述】:

代码:

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 没有响应
  • 如果我输入“你好”,机器人会回答
  • 问题出在哪里?

【问题讨论】:

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


    【解决方案1】:

    覆盖默认提供的on_message 禁止运行任何额外的命令。要解决此问题,请在 on_message 末尾添加 bot.process_commands(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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 2019-10-23
      • 2023-02-10
      • 2020-09-12
      • 2021-04-09
      • 2021-10-06
      相关资源
      最近更新 更多