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

问题描述 投票:0回答:1

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

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);


}

我希望编辑该消息。

javascript discord discord.js
1个回答
0
投票

搞定了。

用过这个:

message.channel.fetchMessages({around: msgId, limit: 1})
    .then(msg => {
        const fetchedMsg = msg.first();
        fetchedMsg.edit(embed);
    });
© www.soinside.com 2019 - 2024. All rights reserved.