discord.py无法识别命令

时间:2019-03-09 05:13:46

标签: python discord

我尝试使用.ping进行了简单的discord.py设置,但是在当前情况下,实际发送的“ .ping”导致该机器人未发送任何内容。这里有我想念的东西吗?

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix = ".")


@bot.event
async def on_ready():
    print("Everything's all ready to go~")

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

@bot.event
async def on_message_delete(message):
    author = message.author
    channel = message.channel
    await bot.send_message(channel, message.content)

@bot.command()
async def ping():
    await bot.say('Pong!')

bot.run('Token')

1 个答案:

答案 0 :(得分:0)

确保await bot.process_commands(message)事件中有on_message个地方。

  

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

     

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

     
@bot.event
async def on_message(message):
   # do some extra stuff here

    await bot.process_commands(message)

https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working