如何找到用户不和谐回复的消息内容

时间:2021-04-17 03:02:57

标签: discord discord.js

我目前正在开发一个将消息固定在文本文件中以绕过 Discord 服务器中的消息固定限制的机器人,我的系统通过让用户使用 -pin 回复消息来工作,它将保存该消息和文本文件中的消息作者。问题是我不知道如何获取回复消息的内容和所述消息的作者。任何帮助将不胜感激。

if(command === 'pin'){
    message.channel.send('Ok, pinning that. Use -seepins to see all the pins.'),
    //i have no clue how to get the message that was replied to please help let pinned = 
    //im begging you please i have no idea let pinnedauthor = message.
    fs.writeFile('messages.txt', pinned + ' written by ' + pinnedauthor + '\n', (err) => {
        if (err) throw err;
    });
}

这是我目前拥有的。我只需要找出如何获得第一段中提到的两件事就可以了。

感谢您提供任何帮助,并感谢您阅读本文。

1 个答案:

答案 0 :(得分:0)

当您收到消息对象时,您有一个名为引用的变量。如果您的消息是回复引用,则不应为空,并包含 channelID、guildID、messageID 的 id。

这样你就可以得到前一条消息的消息内容,一行看起来像

client.on('message', 异步消息 => { const RespondTo = await message.channel.messages.fetch(message.reference.messageID);

console.log(repliedTo.content); }); 请注意 message.reference.messageID 您必须添加错误处理以避免在查找未定义变量时崩溃。