【问题标题】:I can't edit a message in another text channel我无法在另一个文本频道中编辑消息
【发布时间】:2020-08-28 04:54:49
【问题描述】:

我正在尝试使用此代码编辑我的机器人(今天)发送的嵌入消息:

const args = message.content.slice(prefix.length).split(' ');
if (!args.length) {
    return message.channel.send('Non hai specificato il messaggio!');
}

const nuovoMsg = args.slice(3).join(' ');
const chId = args[1];
const msgId = args[2];

const messaggioNuovo = new Discord.MessageEmbed()
    .setColor('#c95f34')
    .setDescription(`${nuovoMsg}`);

const msgc = message.guild.channels.cache.get(chId).messages.cache.get(msgId);
msgc.edit(messaggioNuovo);

在我发送的 Discord 文本频道中:

njb!embede 709683421210869842 709711387324317746 Prova della modifica

控制台错误:

TypeError: Cannot read property 'edit' of undefined
    at Object.execute (C:\NNJPBot\commands\embede.js:32:8)
    at Client.<anonymous> (C:\NNJPBot\index.js:81:11)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\NNJPBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\NNJPBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\NNJPBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\NNJPBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\NNJPBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\NNJPBot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:315:20)

信息: 新泽西! : 前缀

嵌入:命令

【问题讨论】:

  • 我看不到message.guild.channels.cache.get(...).messages.cache.fetch 的调用位置。您能否显示导致错误的代码(embede.js:30:70)?
  • 对不起,错误的代码和错误。现在我已经修好了。再次抱歉!

标签: discord.js


【解决方案1】:

发生的情况是消息缓存没有带有msgId 的消息。默认情况下,Discord.js 每个通道最多缓存 200 条消息,因此很可能带有 msgId 的消息已从缓存中删除。

您需要获取消息:

// With await (requires it to be in an async function)
const msgc = await message.guild.channels.cache.get(chId).messages.fetch(msgId)
msgc.edit(messaggioNuovo)

// With then
message.guild.channels.cache.get(chId).messages.fetch(msgId).then(msgc =>
  msgc.edit(messaggioNuovo)
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    相关资源
    最近更新 更多