【问题标题】:How do I find the content of a message that a user replied to in discord如何找到用户不和谐回复的消息内容
【发布时间】:2021-04-17 11:08:11
【问题描述】:

我目前正在开发一个将消息固定在文本文件中以绕过不和谐服务器中的消息 pin 限制的机器人,我的系统通过让用户使用 -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;
    });
}

这是我目前拥有的。我只需要找出如何获得第一段中提到的两件事,它应该可以工作。

感谢您的帮助,感谢您阅读本文。

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 2021-02-04
      • 2021-02-12
      • 1970-01-01
      相关资源
      最近更新 更多