Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

discord.js | Reply to Message (Actual Reply with Reply Decoration)

Recently, Discord added new functionality that when a user replies to a message, it quotes it and adds a little line that the replier's profile picture with the original sender's profile picture and message, as seen here (me replying to a message from a bot):

Message reply screenshot

Is it possible to do it with Discord.js?

Currently, I've no problem using message.reply(), however the bot just sends a message, rather than actually reply to it (sends a "reply-typed" message), which is what is shown when I reply to a message via the app's GUI, manually (as shown above).

like image 847
Gal Grünfeld Avatar asked Dec 02 '20 18:12

Gal Grünfeld


People also ask

How do you reply to a message in Discordjs?

How do you code a Discord BOT to respond to messages? To reply to a message, use message. reply : @client.

How do you reply to your own message on discord?

Hover your cursor over the comment so a bar of icons appears to the right of the message. In this bar, click the arrow icon — or if the arrow isn't there, like if you're replying to your own comment, click the ellipsis icon, and then the "Reply" option.

How do you mention discord in Javascript?

Discord uses a special syntax to embed mentions in a message. For user mentions, it is the user's ID with <@ at the start and > at the end, like this: <@86890631690977280> . If they have a nickname, there will also be a ! after the @ . Role mentions and channel mentions work similarly.


Video Answer


5 Answers

Discord.js will support inline replies in version 13, replacing Message#reply with the new functionality. If you want to try the feature ahead of time, please install and test this PR: https://github.com/discordjs/discord.js/pull/4874. We are always happy to receive bug reports before features are released! (As per usual the ETA on v13 is "when it's ready")

The maintainers of the djs module have made a comment about this in the official djs server's faq channel. This feature is expected to be implemented only in version 13, if you want to implement this you have to fork djs and write your own reply code to use the message reference parameter in the official discord API gateway

like image 141
Jytesh Avatar answered Oct 22 '22 00:10

Jytesh


In Discord.JS versions 13+ you can now use the Message#reply() method to send inline replies.

Docs

message.reply("woohoo, inline reply support!").then(/* ... */).catch(console.error);
like image 26
adrian Avatar answered Oct 22 '22 00:10

adrian


You can do this:

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
    }
  }
})
like image 7
MrMythical Avatar answered Oct 22 '22 00:10

MrMythical


Using discord-reply: https://www.npmjs.com/package/discord-reply

Main file

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');

On command handler

/**
 * No need to define it
 * */
module.exports = {
  name: 'reply',
  category: 'Test',
  run: (client, message, args) => {
    message.lineReply('This is reply with @mention');
  }
}
like image 6
Angelo II Avatar answered Oct 21 '22 22:10

Angelo II


According to version 12 of Discord.js, this behavior does not seem to be supported yet. See: https://discord.js.org/#/docs/main/master/class/Message

like image 1
dolor3sh4ze Avatar answered Oct 21 '22 22:10

dolor3sh4ze