每5分钟更新一次嵌入消息(discord.py)

编程入门 行业动态 更新时间:2024-10-19 00:21:40
本文介绍了每5分钟更新一次嵌入消息(discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望我的机器人永远每5分钟更新一次他的嵌入消息,这有可能吗?

I wanted my bot to update his embed message every 5 minutes for ever, is that possible?

就像我一样!更新消息

例如,我的机器人发送了已编程的消息标题:数字描述:此消息每5分钟更新一次添加字段:名称:Number;值:str(num)

And my bots sends the message programmed for example Title: Numbers Description: This message updates every 5 minutes Add field: name: Number ; value: str(num)

num = 0num = num + 1#如何变大

num=0 num=num+1 # How it gets bigger

推荐答案

首先,您可以查看那个.

然后,这就是我的做法.使其适应您的需要(也请注意,这是 rewrite 分支中的代码.如果您使用的是 latest ,我真的建议您迁移到 rewrite ,因为不建议使用 latest 并且其开发处于待命状态):

Then, here's how i would do it. Adapt it to your need (also, note that this is code from the rewrite branch. If you're using latest i really much advice you to migrate to rewrite as latest is deprecated anyway and its developpement is in standby) :

async def my_background_task(): await client.wait_until_ready() while not client.is_closed(): message = await client.get_channel(channelId).fetch_message(messageId) await message.edit(embed = newEmbed) await asyncio.sleep(300) bg_task = client.loop.create_task(my_background_task())

NB :不要忘记用消息所在的频道ID替换 channelId ,用消息的ID替换 messageId 您要编辑的邮件,并通过更改后的嵌入

newEmbed

NB : Don't forget to replace channelId by the id of the channel the message is in, messageId by the id of the message you want to edit and newEmbed by the changed embed

更多推荐

每5分钟更新一次嵌入消息(discord.py)

本文发布于:2023-11-27 07:34:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   discord   py

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!