我正在尝试将Dank Memer在discord.py中的automeme作为Red,的齿轮,这是一个自托管的开源不和谐机器人。我有一些非常简单的代码来获取表情包:
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,如果它有帮助的话。
发布于 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与其相应的等待时间配对:
myDict = {7473839655739: 5} # channel id: wait time in seconds
channelID = ctx.channel.id
await asyncio.wait(myDict[channelID]) # waits for 5 seconds发布于 2021-10-09 03:51:12
我修复了它并测试了它!我相信它会成功的!
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)https://stackoverflow.com/questions/62777985
复制相似问题