![](/img/trans.png)
[英]How to edit the time remaining every 10 seconds in an embed in discord.py v1.4.1
[英]Discord.py | Send an embed and edit it every 60 seconds
我想創建一個 discord 機器人,它從 API 檢索數據,然后將數據作為嵌入不和諧的消息發送。 但是,API 上的信息發生了變化,我希望嵌入的消息通過每 60 秒更新一次消息內容來保持最新。
最大的問題是我有其他命令,機器人可能會在 60 秒內發送多條消息。 我如何跟蹤該消息並在需要時對其進行編輯? 這可以通過單個后台任務完成嗎?
*注意:我不介意使用 webhook 或類似的東西。 我只想完成工作。
是的。 使用tasks.loop
。 要開始循環,請使用start()
。 我用一個命令來做到這一點。
@tasks.loop(minutes=1)
async def send_message_loop():
msg = ...
await msg.edit(content="World!")
@bot.command()
async def start(ctx):
send_message_loop.start()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.