无法识别的命令不和谐.py

2024-04-25 07:21:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的问题不和谐.py设置尝试使用.ping,但在当前实例中,实际发送“.ping”将导致bot不发送任何内容。有什么我不知道的吗?你知道吗

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')

Tags: importeventmessageasyncondefbotchannel
1条回答
网友
1楼 · 发布于 2024-04-25 07:21:25

确保在on_message事件中有await bot.process_commands(message)。你知道吗

Why does on_message make my commands stop working?

Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message. For example:

@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

相关问题 更多 >