Discord.JS fetchMessage()

zEx*_*rem 0 javascript fetch node.js discord.js

I have a problem with my Discord.JS Bot, I wanna to edit a embed in a spefic guild and channel, but when I try to run the commands, it errors out with this

/root/my-bot/my-bot.js:550
    guild.channels.get(channel).fetchMessage(user).edit(newMessage);
                               ^

TypeError: Cannot read property 'fetchMessage' of undefined
at Client.<anonymous> (/root/my-bot/my-bot.js:550:31)
at Client.emit (events.js:315:20)
at MessageCreateHandler.handle (/root/my-bot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/root/my-bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/root/my-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/root/my-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/root/my-bot/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (/root/my-bot/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:315:20)
Run Code Online (Sandbox Code Playgroud)

Here's my command code:

 if(message.content.startsWith(prefix + "edit"))
 {
     message.delete();
     let guild = client.guilds.get('server-id')
     const channel = args[0];
     const user = args[1];
     let newMessage = args.slice(2).join(' ');
     guild.channels.get(channel).fetchMessage(user).edit(newMessage);
}
Run Code Online (Sandbox Code Playgroud)

Dae*_*dor 5

> 如果您使用的是 Discord.js v11,问题可能来自于您在命令中提供的频道 ID。
> 看来您尝试从用户获取消息,但方法 .fetchMessage() 将消息 ID作为参数(请参阅Discord.js 文档)。
> 您可以使用 .then(回调函数) 访问获取的消息

使固定

if(message.content.startsWith(prefix + "edit"))
 {
     message.delete();
     let guild = client.guilds.get('server-id');
     const channel = args[0];
     const messageId = args[1];
     let newMessage = args.slice(2).join(' ');
     let fetchedChannel = guild.channels.get(channel);
     if (!fetchedChannel) return console.log('Channel not found');
     fetchedChannel.fetchMessage(messageId).then(message => {
         message.edit(newMessage);
     }).catch(error => console.error(error));
}
Run Code Online (Sandbox Code Playgroud)