繁体   English   中英

Python discord bot 使用 discord.py 问题

[英]Python discord bot using discord.py problem

我正在尝试使用模块 discord.py 制作 discord 机器人,但我遇到了一个问题,我无法修复它。 我想要做的是,当有人 ping 机器人时,他会回答他的前缀,我可以使用:

@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-does-on-message-make-my-commands-stop-working

暂无
暂无

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

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