繁体   English   中英

discord.py 命令没有响应

[英]discord.py command not responding

代码:

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

覆盖默认提供的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")

为什么 on_message 使我的命令停止工作?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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