我怎样才能让我的帮助命令“重置”而不用做一百万个 wait_fors?不和谐.py

时间:2021-02-20 11:22:40

标签: python discord discord.py

这是我的帮助命令:

@client.command(pass_context=True, aliases=['cmd', 'commands'])
async def help(ctx):
    embed = discord.Embed(colour=discord.Colour.blurple())
 
    embed=discord.Embed(title="", description="This is a list of everything Otay! can do! If you need additional help with Otay! join the [**support server**](https://discord.gg/Wa9DpJGEKv)", color=0x7289da)
    embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/776181059757932615/784819540496351233/otay2.png")
    embed.add_field(name='`?` ***Fun***', value='`8ball`, `coinflip`, `dice`, `joke`, `say`, `fact`, `ss`', inline=False)
    embed.add_field(name='`⚒️` ***Moderation***', value='`kick`, `ban`, `unban`, `nick`, `purge`, `slowmode`, `mute`, `unmute`, `lock`, `unlock`', inline=False)
    embed.add_field(name='`⚠️` ***Setup***', value='`prefix`, `welcome`', inline=False)
    embed.add_field(name='`?️` ***Games***', value='`rps`, `tictactoe`', inline=False)
    embed.add_field(name='`?` ***Giveaway***', value='`gstart`', inline=False)
    embed.add_field(name='`?` ***Images***', value='`cat`, `dog`, `fox`, `koala`, `panda`, `meme`, `blursed`', inline=False)
    embed.add_field(name='`?` ***Utilities***', value='`avatar`, `ping`, `poll`, `serverinfo`, `botinfo`, `userinfo`, `bitcoin`, `snipe`, `createinvite`, `password`', inline=False)
    embed.add_field(name="`?` ***Ticket***", value="`configureticket`", inline=False)
    embed.set_footer(icon_url=f"https://cdn.discordapp.com/attachments/776181059757932615/784819540496351233/otay2.png", text=ctx.author)
    embed.timestamp = datetime.datetime.now()
    msg = await ctx.send(embed=embed)
 
    def checkifnotbot(reaction, user):
        return user != client.user
 
    await msg.add_reaction('?')
    await msg.add_reaction('⚒️')
    await msg.add_reaction('⚠️')
    await msg.add_reaction('?️')
    await msg.add_reaction('?')
    await msg.add_reaction('?')
    await msg.add_reaction('?')
    await msg.add_reaction('?')
    await msg.add_reaction('?')
 
    reaction, user = await client.wait_for("reaction_add", check=checkifnotbot)
 
    if str(reaction.emoji) == "?":
      embedfun=discord.Embed(title="`?`Help Fun", color=0x7298da)
      await msg.edit(embed=embedfun)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "⚒️":
      embedmod=discord.Embed(title="`⚒️`Help Moderation", color=0x7298da)
      await msg.edit(embed=embedmod)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "⚠️":
      embedsetup=discord.Embed(title="`⚠️`Setup", color=0x7289da)
      embedsetup.timestamp = datetime.datetime.now()
      await msg.edit(embed=embedsetup)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "?️":
      embedgames=discord.Embed(title="`?️Help Games`", color=0x7289da)
      await msg.edit(embed=embedgames)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "?":
      embedgiveaway=discord.Embed(title="`?`Help Giveaway", color=0x7298da)
      await msg.edit(embed=embedgiveaway)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "?":
      embedimages=discord.Embed(title="`?`Help Images", color=0x7298da)
      embedimages.timestamp = datetime.datetime.now()
      await msg.edit(embed=embedimages)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "?":
      embedlinks=discord.Embed(title="`?`Links", color=0x7289da)
      await msg.edit(embed=embedlinks)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "?":
      embedutils=discord.Embed(title="`?`Help Utilities", color=0x7298da)
      embedutils.timestamp = datetime.datetime.now()
      await msg.edit(embed=embedutils)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
    elif str(reaction.emoji) == "?":
      embedticket=discord.Embed(title="`?`Help Ticket", color=0x7289da)
      await msg.edit(embed=embedticket)
      await msg.clear_reactions()
      await msg.add_reaction('↩️')
 
    def checkifbot(reaction, user):
        return user != client.user
 
    reaction, user = await client.wait_for("reaction_add", check=checkifbot)
 
    if str(reaction.emoji) == "↩️":
      await msg.edit(embed=embed)
      await msg.clear_reactions()

我想要发生的事情 嵌入“重置”它会再次添加所有反应,就像您输入 -help 一样工作。 我的问题我不知道如何将其编辑为正常的帮助命令,因为如果它编辑回来并且您需要再次添加反应,您需要制作一百万个wait_for我的尝试

    def checkifbot(reaction, user):
        return user != client.user
 
    reaction, user = await client.wait_for("reaction_add", check=checkifbot)
 
    if str(reaction.emoji) == "↩️":
      await msg.edit(embed=embed)
      await msg.clear_reactions()

这里的问题是我需要制作这么多wait_for,因为如果人们想要查看另一个类别,他们必须再次点击反应。

我试过这样做,但这只是再次发送它而不是编辑它

    def checkifbot(reaction, user):
        return user != client.user
 
    reaction, user = await client.wait_for("reaction_add", check=checkifbot)
 
    if str(reaction.emoji) == "↩️":
      await help(ctx)

那么有没有办法做这样的事情:await msg.edit(help)(ctx)?或者我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以通过创建一个简单的 get_help 函数来解决这个问题,即

async def get_help(ctx):
   return embed
   # whatever u are currently doing in help(ctx), but return embed instead of sending
  
async def add_reactions(msg, ctx):
   #add reactions
   #add wait_for
   
  

async def help(ctx):
   msg = await ctx.send(embed=get_help(ctx))
   await add_reactions(msg, ctx)
   def checkifbot(reaction, user):
        return msg.id == reaction.message.id and user != client.user #improved check
 
    reaction, user = await client.wait_for("reaction_add", check=checkifbot)
 
    if str(reaction.emoji) == "↩️":
      await msg.edit(embed = get_help(ctx))
   

但是,您无需经历这么多麻烦并使用 discord.py 的 HelpCommand。这可能更容易根据需要实施和修改。

相关问题