【问题标题】:discord.js | Reply to Message (Actual Reply with Reply Decoration)不和谐.js |回复消息(实际回复带有回复装饰)
【发布时间】:2021-03-14 18:21:03
【问题描述】:

最近,Discord 添加了新功能,当用户 replies 发送消息时,它会引用该消息并添加一小行,即回复者的个人资料图片与原始发件人的个人资料图片和消息,如此处所示(我回复来自机器人的消息):

是否可以使用 Discord.js 做到这一点?

目前,我使用message.reply() 没有问题,但是机器人只是发送消息,而不是实际回复它(发送“回复类型”消息),这是我回复时显示的内容通过应用程序的 GUI 手动发送消息(如上所示)。

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

djs 模块的维护者已在官方 djs 服务器的 faq 频道中对此进行了评论。此功能预计仅在版本 13 中实现,如果要实现此功能,您必须 fork djs 并编写自己的回复代码以使用官方 discord API 网关中的message reference 参数

【讨论】:

【解决方案2】:

使用不和谐回复:https://www.npmjs.com/package/discord-reply

主文件

const discord = require('discord.js');
require('discord-reply'); //⚠️ IMPORTANT: put this before your discord.Client()
const client = new discord.Client();

client.on('ready', () => {
  console.log(client.user.tag)
});

client.on('message', async message => {
  if (message.content.startsWith('!reply')) {
    message.lineReply('Hey'); //Line (Inline) Reply with mention

    message.lineReplyNoMention(`My name is ${client.user.username}`); //Line (Inline) Reply without mention
  }
});

client.login('TOKEN');

关于命令处理程序

/**
 * No need to define it
 * */
module.exports = {
  name: 'reply',
  category: 'Test',
  run: (client, message, args) => {
    message.lineReply('This is reply with @mention');
  }
}

【讨论】:

    【解决方案3】:

    你可以这样做:

    client.api.channels[message.channel.id].messages.post({
      data: {
        content: "this is my message content!",
        message_reference: {
          message_id: message.id,
          channel_id: message.channel.id,
          guild_id: message.guild.id
        }
      }
    })
    

    【讨论】:

      【解决方案4】:

      根据 Discord.js 的第 12 版,此行为似乎尚不受支持。 见:https://discord.js.org/#/docs/main/master/class/Message

      【讨论】:

      • 谢谢,这是我的想法——我在文档中找不到。你知道 Discord API 本身是否提供它吗?
      • 我想在下个月
      【解决方案5】:

      在 Discord.JS 版本 13+ 中,您现在可以使用 Message#reply() 方法发送内联回复。

      Docs

      message.reply("woohoo, inline reply support!").then(/* ... */).catch(console.error);
      

      【讨论】:

        猜你喜欢
        • 2021-05-07
        • 1970-01-01
        • 2020-10-11
        • 1970-01-01
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        • 2015-08-23
        • 1970-01-01
        相关资源
        最近更新 更多