[英]How can I make my discord bot edit its own last message after data is ready
My discord bot has a command to lookup data from an API and sometimes it takes time so I want my bot to tell the user that. 我的不和谐机器人有一个命令可以从API查找数据,有时这需要时间,所以我希望我的机器人告诉用户。
The initial message is: message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}})
初始消息为:
message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}})
How can I make the bot edit the message with the data after the data embed is ready? 数据嵌入准备好后,如何让机器人用数据编辑消息?
message.channel
.send({embed: { color: 0x80ff00, description: "Looking for data"}})
.then(embed => {
// here `embed` is the message that was sent to the channel
someAsyncOperation().then(data => {
embed.edit({embed: {description: "Found the data: " + data}});
});
});
See TextChannel#send and Message#edit . 请参阅TextChannel#send和Message#edit 。
Using .then: 使用.then:
message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}})
.then(msg => {
msg.edit('Something');
});
Using async await: 使用异步等待:
const msg = await message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}});
msg.edit('data');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.