首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >discord.py格式的Automeme海报(像dank memer)

discord.py格式的Automeme海报(像dank memer)
EN

Stack Overflow用户
提问于 2020-07-07 22:50:42
回答 2查看 2.2K关注 0票数 0

我正在尝试将Dank Memer在discord.py中的automeme作为Red,的齿轮,这是一个自托管的开源不和谐机器人。我有一些非常简单的代码来获取表情包:

代码语言:javascript
复制
    async def memes(self, ctx):
        """Get the dankest memes Reddit has to offer. Soon, you'll be able to specify by subreddit and number of memes"""
        async with aiohttp.ClientSession() as session:
            url = "https://meme-api.herokuapp.com/gimme"
            async with session.get(url) as response:
                response = await response.json()
            embedColor = await ctx.embed_colour()
            embed = discord.Embed(
                title= response['title'],
                url = response['postLink'],
                color = embedColor,
            )
            embed.set_image(url=response['url'])
            embed.set_footer(text=f"r/{response['subreddit']} | Requested by {ctx.author.name} | Enjoy your dank memes!")
            await ctx.send(embed=embed)

我在想,我可以存储发布表情包的频道id和字典中表情包的延迟,我可以在大约5分钟内做到这一点。然而,我不知道如何等待一定的时间,然后在指定的渠道发布表情包。

Red的文档是here,如果它有帮助的话。

EN

回答 2

Stack Overflow用户

发布于 2020-07-07 23:55:30

我们可以像这样得到一个频道:

channel = bot.get_channel(id) # id is an int representing a channel's ID

要将嵌入内容发送到该通道:

await channel.send(embed=embed)

要等待指定时间,请执行以下操作:

await asyncio.sleep(secs) # secs is an int representing the number of seconds to wait for

在您的示例中,您绝对可以使用dict将通道ids与其相应的等待时间配对:

代码语言:javascript
复制
myDict = {7473839655739: 5} # channel id: wait time in seconds
channelID = ctx.channel.id
await asyncio.wait(myDict[channelID]) # waits for 5 seconds
票数 0
EN

Stack Overflow用户

发布于 2021-10-09 03:51:12

我修复了它并测试了它!我相信它会成功的!

代码语言:javascript
复制
async def memes(self, ctx):
  async with aiohttp.ClientSession() as session:
    url = "https://meme-api.herokuapp.com/gimme"

    async with session.get(url) as response:

      response = await response.json()

      embed = discord.Embed(
        title= response['title'],
        url = response['postLink'],
        color = 0x5865F2,
      )

      embed.set_image(url=response['url'])

      embed.set_footer(text=f"r/{response['subreddit']} | Requested by {ctx.author.name} | Enjoy your dank memes!")

      await ctx.send(embed=embed)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62777985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档