javascript - 获取消息(按 ID)并编辑它

标签 javascript discord discord.js

我正在尝试以不同的功能编辑机器人发送的消息。

const msg = message.channel.fetchMessage(msgId);
msg.edit(embed);

没用,因为 msg.edit 不是一个函数。

message.channel.messages.fetch({around: "352292052538753025", limit: 1})
  .then(messages => {
    messages.first().edit("test");
  });

没用,因为 .fetch 不是一个函数。

function update(msgId, time, channelid, prize, winnersInt, message) {

    setTimeout(function(){ 

        let gtime = time/3600000 + " hours remaining!";
        if(time < 3600000) {
            gtime = time/60000 + " minuets remaining!";
        }

        console.log(gtime + "p: " + prize);

        let embed = new Discord.RichEmbed()
            .setColor("#7289da")
                        .setTitle("Giveaway!")
            .addField('Prize: ', prize)
            .addField('Amount of winners: ', winnersInt)
                       .addField('Time: ', gtime)
        const msg = message.channel.fetchMessage(msgId);
        msg.edit(embed);

        time - 60000;

        if(time > 0) {
                 update(msgId, time, channel, prize, winnersInt, message);
        }

    }, 60000);


}

我希望消息被编辑。

最佳答案

旧出版物,但可能对当前正在寻找它的人有所帮助。

对于 V.13 可以这样使用:

<#Channel>.messages.fetch('messageID').then(msg => msg.edit('newMessage'))

我以这种方式对其进行了测试,它运行良好。

关于javascript - 获取消息(按 ID)并编辑它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55773999/

相关文章:

php - Ajax 乡村城市选择菜单 onChange() 不起作用

javascript - 在 typescript 中扩展方法

javascript - 为什么我在运行代码时收到错误 "UnhandledPromiseRejectionWarning"?

javascript - 如何比较用户角色?

node.js - NodeJS 调试在 127.0.0.1 :42457 failed: address already in use error 上启动检查器

javascript - 如何在 GHCJS 上将未装箱的 Vector 转换为 JS TypedArray?

javascript - 为数据表的所有列构造状态对象以进行排序: React JS

c# - Discord.net 向指定用户发送直接消息(PM)

javascript - 如何创建 channel 然后找到ID

javascript - 公会未定义