How Do I Make A Discord.js Bot Actually Reply To A Message?
I've been making a Discord.js (V12) bot that supports the type of command 'say' (please note I'm new to this), but when I use this 'say' command and click 'reply' in a specific mes
Solution 1:
There's no way to do that in v12 but it's possible with an API request more specifically Create Message.
And the field that allows us to reply to a message is message_reference
const fetch = require('node-fetch')
client.on("message", (message) => {
if (message.author.bot) return;
const url = `https://discord.com/api/v8/channels/${message.channel.id}/messages`;
var payload = {
content: "Hello, World!",
tts: false,
message_reference: {
message_id: message.id
}
};
fetch(url, {
method: "POST",
body: JSON.stringify(payload),
headers: {
Authorization: `${client.user?.bot ? "Bot " : ""}${client.token}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}).catch(() => { });
});
Solution 2:
I use a package for discord.js v12 to reply to a message.
If I understand correctly, you want to make something like this?
In npm, install a package called "discord-reply".
npm i discord-reply
Then, where you defined discord.js, require the discord-reply package. Do it like this:
const discord = require('discord.js');
require('discord-reply'); //IMPORTANT: put this before defining the clientconst client = new discord.Client();
Then, instead of message.send or message.reply just use:
message.lineReply('Text goes here')
Hovewer, if you don't want to mention a user with reply, use this:
message.lineReplyNoMention('Text goes here');
As simple as that!
Post a Comment for "How Do I Make A Discord.js Bot Actually Reply To A Message?"