discord.js | 回复留言(实际回复加回复装饰)

Gal*_*eld 9 javascript discord discord.js

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

留言回复截图

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

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

MrM*_*cal 8

你可以这样做:

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
    }
  }
})
Run Code Online (Sandbox Code Playgroud)


Jyt*_*esh 7

Discord.js 将在版本 13 中支持内联回复,用新功能替换 Message#reply。 如果您想提前尝试该功能,请安装并测试此 PR:https://github.com/discordjs/discord.js/pull/4874。 我们总是很高兴在功能发布之前收到错误报告! (按照惯例,v13 上的预计到达时间是“准备就绪时”)

djs 模块的维护者已经在官方 djs 服务器的 faq 频道中对此发表了评论。该功能预计13版本才会实现,如果要实现需要fork djs,自己写回复代码使用官方discord API网关中的消息引用参数

  • 消息内的链接:https://github.com/discordjs/discord.js/pull/4874 (3认同)

小智 6

使用不和谐回复: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');
Run Code Online (Sandbox Code Playgroud)

在命令处理程序上

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