我试图创建一个嵌入模式和文本模式,所以你可以创建两次相同的命令,但它们有不同的输出。
我试过这个:
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)
问题是如果我切换模式它说命令已经存在,但我先删除了齿轮,然后加载了另一个,这就是为什么我感到困惑。 我在这里先向您的帮助表示感谢。 :)
答案 0 :(得分:1)
discord.py 有一个内置的帮助命令。在创建自定义之前,您需要将其删除。
bot.remove_command("help")
另一个好方法是:
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