如何解决如何在discord.py v1.4.1中嵌入的每10秒编辑剩余时间
这是我的代码-
@client.command()
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def giveaway(ctx,duration: int,channel: discord.TextChannel,*,prize: str):
giveaway_embed = discord.Embed(title=f"{str(prize)}",description=f"Hosted by - {ctx.author.mention}\n"
f"**React with :tada: to enter!**"
f"Time Remaining: {duration} seconds",color=ctx.guild.me.top_role.color,)
embed_send = await channel.send(content=":tada: **GIVEAWAY** :tada:",embed=giveaway_embed)
await embed_send.add_reaction("?")
#Every 10 seconds I want to change the Time Remaining: field
我想每5秒钟编辑一次嵌入,直到赠品结束为止,我不太清楚该怎么做,非常感谢您的帮助。谢谢!
解决方法
要等待10秒钟,应使用asyncio.sleep()
,然后使用Message.edit()
方法:
from discord import Embed,TextChannel
from asyncio import sleep
@client.command()
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def giveaway(ctx,duration: int,channel: TextChannel,*,prize: str):
embed = Embed(title=prize,description=f"Hosted by - {ctx.author.mention}\n"
f"**React with :tada: to enter!**"
f"Time Remaining: {duration} seconds",color=ctx.guild.me.top_role.color,)
msg = await ctx.channel.send(content=":tada: **GIVEAWAY** :tada:",embed=embed)
await msg.add_reaction("?")
while duration:
await sleep(10)
duration -= 10
embed.description = f"Hosted by - {ctx.author.mention}\n**React with :tada: to enter!**\nTime Remaining: {duration} seconds"
await msg.edit(embed=embed)
await ctx.send("Giveaway is over!")
PS:我已经导入了TextChannel
和Embed
,所以我替换了discord.TextChannel
和discord.Embed
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。