Discord.js - 在以下代码中更新 MessageEmbed
Discord.js - Updating a MessageEmbed in the following code
所以,我有(这只是其中的一部分)以下代码,但我无法弄清楚整个更新已发送的嵌入内容...
如果我每次都发送一个新的嵌入,编码就可以正常工作,但我不想弄乱频道;因此尝试更新第一个嵌入。
代码:
const filter = m => m.author.id === message.author.id;
let hangembedStart = new Discord.MessageEmbed()
.setDescription("Let's get started!")
.setColor('#0099ff')
.setThumbnail(sicon)
.addField('Word:', asterisc)
message.channel.send(hangembedStart);
const collector = message.channel.createMessageCollector(filter, {
maxMatches: 9,
time: 30000
});
collector.on('collect', m => {
if (m.content === 'cancel') {
inProgress = false;
delete guessed;
collector.stop();
return;
}
if (lowChar === text) {
message.channel.send(`Congratulations, you guessed the word!`);
inProgress = false;
delete guessed;
collector.stop();
return;
}
let hits = checkChar(lowChar, text);
if (hits === 0) {
let hangembedGuess = new Discord.MessageEmbed()
.setDescription("Hangman - The Game - In progress")
.setColor('#0099ff')
.setThumbnail(sicon)
.addField('Word:', reveal)
.addField('Guessed:', guessed.join(" "))
message.channel.send(hangembedGuess);
} else if (hits > 0) {
let hangembedGuess = new Discord.MessageEmbed()
.setDescription("Hangman - The Game - In progress")
.setColor('#0099ff')
.setThumbnail(sicon)
.addField('Word:', reveal)
.addField('Guessed:', guessed.join(" "))
message.channel.send(hangembedGuess);
}
});
collector.on('end', collected => {
message.channel.send(`Game ended, word was: ${text}!`);
inProgress = false;
delete guessed;
//collector.stop();
});
如何...我可以更新此代码中的第一个嵌入,而不是每次都发送一个新的?
我尝试使用 message.edit() 但这会触发:
UnhandledPromiseRejectionWarning:DiscordAPIError:无法编辑由其他用户撰写的消息
我用谷歌搜索、阅读、搜索、尝试、测试了我遇到的几乎所有内容,但无法完全理解这个...
整理好了!!
添加了以下行:
const hangmanMessage = await message.channel.send(hangembedStart);
//above
const filter = m => m.author.id === message.author.id;
然后更改了以下行:
message.channel.send(hangembedGuess);
//to this
hangmanMessage.edit(hangembedGuess);
现在它更新第一个嵌入,而不是每次都发送一个新嵌入:D
所以,我有(这只是其中的一部分)以下代码,但我无法弄清楚整个更新已发送的嵌入内容...
如果我每次都发送一个新的嵌入,编码就可以正常工作,但我不想弄乱频道;因此尝试更新第一个嵌入。
代码:
const filter = m => m.author.id === message.author.id;
let hangembedStart = new Discord.MessageEmbed()
.setDescription("Let's get started!")
.setColor('#0099ff')
.setThumbnail(sicon)
.addField('Word:', asterisc)
message.channel.send(hangembedStart);
const collector = message.channel.createMessageCollector(filter, {
maxMatches: 9,
time: 30000
});
collector.on('collect', m => {
if (m.content === 'cancel') {
inProgress = false;
delete guessed;
collector.stop();
return;
}
if (lowChar === text) {
message.channel.send(`Congratulations, you guessed the word!`);
inProgress = false;
delete guessed;
collector.stop();
return;
}
let hits = checkChar(lowChar, text);
if (hits === 0) {
let hangembedGuess = new Discord.MessageEmbed()
.setDescription("Hangman - The Game - In progress")
.setColor('#0099ff')
.setThumbnail(sicon)
.addField('Word:', reveal)
.addField('Guessed:', guessed.join(" "))
message.channel.send(hangembedGuess);
} else if (hits > 0) {
let hangembedGuess = new Discord.MessageEmbed()
.setDescription("Hangman - The Game - In progress")
.setColor('#0099ff')
.setThumbnail(sicon)
.addField('Word:', reveal)
.addField('Guessed:', guessed.join(" "))
message.channel.send(hangembedGuess);
}
});
collector.on('end', collected => {
message.channel.send(`Game ended, word was: ${text}!`);
inProgress = false;
delete guessed;
//collector.stop();
});
如何...我可以更新此代码中的第一个嵌入,而不是每次都发送一个新的? 我尝试使用 message.edit() 但这会触发: UnhandledPromiseRejectionWarning:DiscordAPIError:无法编辑由其他用户撰写的消息
我用谷歌搜索、阅读、搜索、尝试、测试了我遇到的几乎所有内容,但无法完全理解这个...
整理好了!!
添加了以下行:
const hangmanMessage = await message.channel.send(hangembedStart);
//above
const filter = m => m.author.id === message.author.id;
然后更改了以下行:
message.channel.send(hangembedGuess);
//to this
hangmanMessage.edit(hangembedGuess);
现在它更新第一个嵌入,而不是每次都发送一个新嵌入:D