这是我的代码:
import discord
import asyncio
from discord import Game
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print(bot.user.id)
print("botstart")
game = discord.Game("abc")
await bot.change_presence(status=discord.Status.online, activity=game)
@bot.event
async def on_message(message):
if message.content.startswith("hi"):
await message.channel.send("Hello")
if message.content.startswith("ping"):
await message.channel.send("Pong")
@bot.command
async def ping(ctx):
ctx.send("Pong!")
bot.run("(my token)", bot=True)
由于某些原因,bot.event
有效,而@bot.command(!ping)
部分无效。我试图修复它,但我什至没有看discord.py指南。
我在做什么错了?
答案 0 :(得分:1)
由于您要覆盖on_message事件,因此漫游器不再响应任何命令。要解决此问题,请在您的on_message函数中添加await bot.process_commands(message)
以便其正常处理命令。