[英]discord.js how to edit/update embed?
I'm working on a "small" bot for fun and currently trying to create a blackjack command.我正在开发一个“小型”机器人以获取乐趣,目前正在尝试创建一个二十一点命令。 The first half works fine, but the problem appears when I want to update the embed that was already posted by the bot.
前半部分工作正常,但是当我想更新机器人已经发布的嵌入时会出现问题。 I keep getting an error:
UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user
Here is part of the code:我不断收到错误消息:
UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user
这是部分代码:
const embd = new Discord.MessageEmbed()
.addFields(
{ name: 'Dealer cards: ' + botCards + ' + ?'},
{ name: 'Your cards: ' + userCards},
)
message.channel.send(embd).then(embdReact => {
embdReact.react('🟩');
embdReact.react('🟥');
const filter = (reaction, user) => {
return ['🟩','🟥'].includes(reaction.emoji.name) && user.id === message.author.id;
};
embdReact.awaitReactions(filter, { max: 1, time: 60000})
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '🟩'){
const newEmbd = new Discord.MessageEmbed()
.setTitle("Wow");
message.edit(newEmbd);
}
else {
message.reply('boo');
}
})
})
For testing I tried to change just the title, but in the perfect world a corresponding field would be updated.为了进行测试,我尝试仅更改标题,但在完美的世界中,相应的字段将被更新。 Ex: "Your cards:" field.
例如: “你的卡片:”字段。
You're editing the wrong message:您正在编辑错误的消息:
The line:该行:
message.edit(newEmbd);
should be:应该:
embdReact.edit(newEmbd);
Hope this will help you to fix your issue !希望这可以帮助您解决问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.