Python discord-bot使用discord.py问题



我正试图使用模块discord.py制作一个discordbot,但我遇到了一个问题,无法修复。我想做的是,当有人ping到bot时,他会回答他的前缀,我使用

@bot.event
async def on_message(message):
if bot.user.mentioned_in(message):
await message.channel.send("My prefix is **_#_**")

然而,之后的代码都不起作用:

@bot.command(name="ping")
async def ping(ctx):
await ctx.send('Pong! {0}'.format(round(bot.latency, 1)))
@bot.command(name='get')
async def get(ctx, arg: to_lower):
if (arg == "taurine"):
author = "CoolStar"
version = "1.0.4"
size = "31MB"
url = "https://www.yot-dev.ml/ipas/taurine.ipa"
if arg == "unc0ver":
author = "Pwn20wnd"
version = "6.1.2"
size = "59MB"
url = "https://www.yot-dev.ml/ipas/unc0ver.ipa"
if arg == "cercube5":
author = "Majd Alfhaily"
version = "16.19.6"
size = "101MB"
url = "https://www.yot-dev.ml/ipas/unc0ver.ipa"
@bot.event
async def on_command_error(ctx, error):
if get(error, commands.CommandNotFound):
await ctx.send("Please enter a valid argument.")
text.description = "**["+str.capitalize(arg)+" IPA download link]""("+url+")**nAuthor: "+author+"nVersion: "+version+"nSize: "+size
await ctx.send(embed=text)
bot.run(os.getenv("TOKEN"))

,所以除了提及/ping机器人程序之外,我不能使用任何命令。很高兴知道是否有可能解决这个问题。

您可能需要将其添加到您的on_message命令中,如文档中所述:

else:
await bot.process_commands(message)

https://discordpy.readthedocs.io/en/latest/faq.html#why-在消息上是否使我的命令停止工作

最新更新