【问题标题】:Creating meme command with discord.py使用 discord.py 创建 meme 命令
【发布时间】:2022-01-09 14:20:07
【问题描述】:

谁能帮我创建像 dank memer 这样的 meme 命令。下面是我要制作的命令的照片。 enter image description here

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    这是我现在使用的 meme 命令。这也类似于 dank memer。 这是来自 discord_compoenents 库。您可以参考文档以使用该按钮

    
        @commands.command(aliases=['me'])
        @commands.guild_only()
        @commands.cooldown(1, 3, commands.BucketType.user)    
        async def meme(self,ctx):
          serverId = ctx.message.guild.id    
          def meme_opt():
                choices=[1,2]
                chosen=random.choice(choices)
                if(chosen==1):
                  '''Post a meme'''
                  r = requests.get("https://memes.blademaker.tv/api?lang=en")
                  res = r.json()
                  title = res["title"]
                  ups = res["ups"]
                  # downs = res["downs"]
                  comments = res['score']
                  authors=res["author"]
                  memes = discord.Embed(title=f"{title}",colour=randint(0, 0xffffff))
                  memes.set_image(url=res["image"])
                  memes.set_footer(text=f"? : {ups}  ✍️ : {authors}   ? : {comments} ")
                else:
                  ###################
                  r=requests.get("https://meme-api.herokuapp.com/gimme")
                  res=r.json()
                  title=res["title"]
                  ups=res["ups"]
                  author=res["author"]
                  link=res["postLink"]
                  memes = discord.Embed(description=f"[{title}]({link})",colour=randint(0, 0xffffff))
                  memes.set_image(url=res["url"])
                  memes.set_footer(text=f"? : {ups} ✍️ : {author}")
                return memes
    
          components = [
              [
                  Button(label='Next meme', style=ButtonStyle.green, custom_id='next'),
                  Button(label='End interaction', style=ButtonStyle.red, custom_id='exit')
              ]
          ]
    
          message = await ctx.send(embed=meme_opt(), components=components)
          id=message.id
          while True:
              try:
                  interaction = await self.bot.wait_for(
                      'button_click',
                      check=lambda inter: inter.message.id == message.id,
                      timeout=30
                  )
              except asyncio.TimeoutError:
                  for row in components:
                      row.disable_components()
                  return await message.edit(components=components)
    
              if(interaction.author.id==ctx.author.id):
                    if(interaction.custom_id=="next"):
                      await interaction.edit_origin(embed=meme_opt(),components=components)
                    elif(interaction.custom_id=="exit"):
                      for row in components:
                        row.disable_components()
                      message=await ctx.fetch_message(id)   
                      return await interaction.edit_origin(embed=message.embeds[0],components=components)
              else:
                await interaction.send("Hey! This is not for you!")
    

    【讨论】:

    • 如果对你有用,请考虑接受我的回答
    猜你喜欢
    • 2021-08-28
    • 2019-07-30
    • 2021-07-05
    • 2021-07-27
    • 2021-08-17
    • 2020-11-24
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多