【问题标题】:Discord.js - Updating a MessageEmbed in the following codeDiscord.js - 在以下代码中更新 MessageEmbed
【发布时间】:2020-11-22 21:25:08
【问题描述】:

所以,我有(这只是其中的一部分)以下代码,但我无法弄清楚整个更新已发送的嵌入内容...

如果我每次都发送一个新的嵌入,编码就可以正常工作,但我不想弄乱频道;因此尝试更新第一个嵌入。

代码:

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:无法编辑由其他用户创作的消息

我已经在谷歌上搜索、阅读、搜索、尝试、测试了我遇到的所有内容,但无法完全理解这个......

【问题讨论】:

  • 你是如何触发消息发送的?它可能不起作用的原因是因为您正在尝试编辑该人发送的消息,而不是编辑机器人发送的嵌入。
  • 嗯,我怀疑这也是问题所在。这是代码; ```
  • 代码在哪里
  • 代码太长,无法发表评论,但我将其发布在 Pastebin 上。 pastebin.com/YpJk0sJD
  • 您可以获取机器人在频道中发送的最后一条消息并进行编辑

标签: node.js discord.js embed updates message


【解决方案1】:

整理好了!!

添加了以下行:

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

【讨论】:

    猜你喜欢
    • 2022-01-01
    • 1970-01-01
    • 2020-07-11
    • 2021-09-04
    • 2021-10-26
    • 2020-12-19
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    相关资源
    最近更新 更多