我希望我的机器人永远每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)
发布评论