Switch between Modes

Viewed 47

I was trying to make an Embed-mode and Text-mode, so you can make the same command twice but they have a different output.

I tried this:

class text(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def help(self, ctx):
        await ctx.message.delete()
        await ctx.send(f'''```diff
user - Shows user commands
utility - Shows utility commands
fun - Shows fun commands
settings - Shows setting commands```''')

class embed(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()  
    async def help(self, ctx):
        await ctx.message.delete()
        embed=discord.Embed(title="Help Menu", color=0x8c00ff)
        embed.add_field(name="`user`", value="shows user commands", inline=False)
        embed.add_field(name="`utility`", value="shows utility commands", inline=False)
        embed.add_field(name="`fun`", value="shows fun commands", inline=False)
        embed.add_field(name="`settings`", value="shows settings commands", inline=False)
        embed.set_footer(text="Help Menu")
        await ctx.send(embed=embed)

@bot.command()
async def textmode(ctx):
    await ctx.message.delete()
    bot.remove_cog(embed(bot))
    bot.add_cog(text(bot))


@bot.command()
async def embedmode(ctx):
    await ctx.message.delete()
    bot.remove_cog(text(bot))
    bot.add_cog(embed(bot))

mode_s = config.get("mode")

def modes(bot):
    if mode_s == "1":
        bot.remove_cog(embed(bot))
        bot.add_cog(text(bot))
    elif mode_s == "2":
        bot.remove_cog(text(bot))
        bot.add_cog(embed(bot))

modes(bot)

The problem is if i switch modes it says that the command already exists, but I removed the cog first and then loaded the other thats why I am confused. Thanks for the help in advance. :)

1 Answers

there is a built in help command for discord.py. before creating a custom one, you need to remove it.

bot.remove_command("help")

another good way of doing this is:

text_mode = True

@bot.command()
async def help(self, ctx):
    await ctx.message.delete()
    if text_mode:
        await ctx.send(f'''```diff
user - Shows user commands
utility - Shows utility commands
fun - Shows fun commands
settings - Shows setting commands```''')
    else:
        embed=discord.Embed(title="Help Menu", color=0x8c00ff)
        embed.add_field(name="`user`", value="shows user commands", inline=False)
        embed.add_field(name="`utility`", value="shows utility commands", inline=False)
        embed.add_field(name="`fun`", value="shows fun commands", inline=False)
        embed.add_field(name="`settings`", value="shows settings commands", inline=False)
        embed.set_footer(text="Help Menu")
        await ctx.send(embed=embed)

@bot.command()
async def textmode(ctx):
    await ctx.message.delete()
    text_mode = not text_mode

Related