Skip to content
Advertisement

Python discord bot using discord.py problem

I’m trying to make a discord bot using the module discord.py, but I’m running into an issue and I’m unable to fix it. What I’m trying to do is that when someone pings the bot, he answers his prefix, I got that working with :

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

However none of the code after that works:

@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"))

, so I cannot use any commands other than mentioning/pinging the bot. Would be nice to know if it’s possible to fix this.

Advertisement

Answer

You probably need to add this here to your on_message command as described in the docs:

else:
    await bot.process_commands(message)

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement