edit message doesnt work discordpy (nextcord)

Viewed 197

Im making this command where if i said =help fun, fun commands should show up and if i said =help economy, economy commands should show up too. But this code doesnt work any fixes?

    @commands.command()
    async def help(self, ctx, arg1):
        if arg1 != "fun":
            return
        else:
            #Help fun
            embedFun = nextcord.Embed(
                title="Need help?",
                description="Fun: ",
                color=nextcord.Color.green())

            embedFun.set_thumbnail(url="https://www.freeiconspng.com/thumbs/money-icons/money-icon-29.png")

            embedFun.add_field(
                name="`=howsimp`",
                value="Shows how simp you or your friends are.",
                inline=False
            )
            embedFun.add_field(
                name="`=help economy`",
                value="Shows you the economy category commands.",
                inline=False
            )   
            funHelp = await ctx.reply(embed=embedFun)

        if arg1 != "economy":
            return
        else:
           #Help economy
            embedEconomy = nextcord.Embed(
                title="Need help?",
                description="Economy: ",
                color=nextcord.Color.green())

            embedEconomy.set_thumbnail(url="https://www.freeiconspng.com/thumbs/money-icons/money-icon-29.png")

            embedEconomy.add_field(
                name="`=balance`",
                value="Shows how simp you or your friends are.",
                inline=False
            )
            embedEconomy.add_field(
                name="`=help economy`",
                value="Shows you the economy category commands.",
                inline=False
            )   
            await funHelp.edit(embed=embedEconomy)

btw im using discord.py's fork "nextcord"


2 Answers
  1. you should not use this weird "if != else" structure. Use elif or Structural Pattern Matching.

  2. funHelp is not a global variable therefore .edit is called to a NoneType

  3. to accomplish what you are trying try .history or buttons

before filling out the content for if-else clauses, it is better to write conditional blocks first to see logic problems. your code have this beginner's issue. currently, for any case other than fun, it immediately exits empty and will return a result only for =help fun.

    if arg1 != "fun":
        return
    else:
        #Help fun
    if arg1 != "economy":
        return
    else:
       #Help economy

the following is the correct way. you can also use if-elif-else blocks

    if arg1 == "fun":
       #Help fun
    if arg1 == "economy":
       #Help economy
    return

or

    if arg1 == "fun":
       #Help fun
    elif arg1 == "economy":
       #Help economy
    else:
       return

I haven't checked your code for frameworks problems. if this does not fix your problem, let me know for another look.

Related