Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating meme command with discord.py

Can someone help me how to create meme command like dank memer. Below is the photo of the command i want to make.
enter image description here

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the meme command I am using now. This is also similar to dank memer.
This is from the library of discord_compoenents. You can refer the docs for using the button


    @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!")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading