discord.js查找并编辑dm. 中的消息



我试图在dm中找到消息并通过discord.js编辑它,但我无法做到我的代码:

const User = client.users.cache.get(usrid);
if (!User.dmChannel) return console.log("No messages found.");
// Getting the message by ID
User.dmChannel.messages.fetch(lastmsgid).then(dmMessage => {
// Editing the message.
dmMessage.edit(`${dmMessage.content}n${messageToSend}`);

错误:

readline.js:1147
throw err;
^
TypeError: Cannot read property 'dmChannel' of undefined
at C:UsersShankarDesktopbotDisgd-haxindex.js:29:35
at Interface._onLine (readline.js:327:5)
at Interface._line (readline.js:658:8)
at Interface._ttyWrite (readline.js:1003:14)
at ReadStream.onkeypress (readline.js:205:10)
at ReadStream.emit (events.js:315:20)
at emitKeys (internal/readline/utils.js:335:14)
at emitKeys.next (<anonymous>)
at ReadStream.onData (readline.js:1137:36)
at ReadStream.emit (events.js:315:20)

如果usrid被正确使用并且是一个用户id,这意味着您当前正在获取用户id并获得用户结果,而不是dm通道或dm消息,能够这样做。

我建议使用这里提到的messages.fetch方法

相关内容

  • 没有找到相关文章