Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Discord.js v12 Inline Replies
const { APIMessage, Structures } = require("discord.js");
class ExtAPIMessage extends APIMessage {
resolveData() {
if (this.data) return this;
super.resolveData();
const allowedMentions = this.options.allowedMentions || this.target.client.options.allowedMentions || {};
if (allowedMentions.repliedUser !== undefined) {
if (this.data.allowed_mentions === undefined) this.data.allowed_mentions = {};
Object.assign(this.data.allowed_mentions, { replied_user: allowedMentions.repliedUser });
}
if (this.options.replyTo !== undefined) {
Object.assign(this.data, { message_reference: { message_id: this.options.replyTo.id } });
}
return this;
}
}
class Message extends Structures.get("Message") {
inlineReply(content, options) {
return this.channel.send(ExtAPIMessage.create(this, content, options, { replyTo: this }).resolveData());
}
edit(content, options) {
return super.edit(ExtAPIMessage.create(this, content, options).resolveData());
}
}
Structures.extend("Message", () => Message);
const { Client } = require("discord.js");
require("./ExtendedMessage");
const client = new Client({
allowedMentions: {
// set repliedUser value to `false` to turn off the mention by default
repliedUser: true
}
});
client.on("message", msg => {
if (msg.author.bot) return;
if (msg.content === "hi") {
msg.inlineReply("hello");
}
});
client.login("ur token");
@Allvaa
Copy link
Author

Allvaa commented Apr 20, 2021

updated. you guys must add the allowed mentions options like the inlineReply one when editing messages 👀

@Rapougnac
Copy link

Rapougnac commented Apr 24, 2021

Here's another bug;

-Create an embed;
-Send the embed with the { allowedMentions: { repliedUser: false } } or { allowedMentions: { repliedUser: true } };
-And the bot is replying [object Object]

But without the options passed, the embed is correctly send

@Allvaa
Copy link
Author

Allvaa commented Apr 24, 2021

Here's another bug;

-Create an embed;
-Send the embed with the { allowedMentions: { repliedUser: false } } or { allowedMentions: { repliedUser: true } };
-And the bot is replying [object Object]

But without the options passed, the embed is correctly send

it's a discord.js bug when passing the first parameter with embed and pass the 2nd parameter with options.
read this https://gist.github.com/Allvaa/0320f06ee793dc88e4e209d3ea9f6256#gistcomment-3661159

@Alespren
Copy link

Alespren commented Apr 29, 2021

or you can make it default by changing the true to false in
https://gist.github.com/Allvaa/0320f06ee793dc88e4e209d3ea9f6256#file-extendedmessage-js-L5

I am confused, there is no 'true' on that line. Has the code changed since you made this comment?

@Alespren
Copy link

Alespren commented Apr 29, 2021

Found a solution to default mention settings!

// Add this to the '(this.options.allowedMentions || {}).repliedUser !== undefined' if statement
else {
     // Changing replied_user to true will turn mentions on by default
     this.data.allowed_mentions = { replied_user: false }
}

This allows you to change the default mention setting. If it's set to false, mentions will be off by default. If it's set to true, they will be on by default.

@Allvaa
Copy link
Author

Allvaa commented Apr 29, 2021

or you can make it default by changing the true to false in
https://gist.github.com/Allvaa/0320f06ee793dc88e4e209d3ea9f6256#file-extendedmessage-js-L5

I am confused, there is no 'true' on that line. Has the code changed since you made this comment?

oh, lol. sorry, that's a comment before the code was changed

@Allvaa
Copy link
Author

Allvaa commented Apr 29, 2021

Found a solution to default mention settings!

// Add this to the '(this.options.allowedMentions || {}).repliedUser !== undefined' if statement
else {
     // Changing replied_user to true will turn mentions on by default
     this.data.allowed_mentions = { replied_user: false }
}

This allows you to change the default mention setting. If it's set to false, mentions will be off by default. If it's set to true, they will be on by default.

thanks! <3 but i prefer to use Object.assign instead of assigning it directly, it just makes the this.data.allowed_mentions overwritten and causes other mention settings to disappear

@Allvaa
Copy link
Author

Allvaa commented Apr 29, 2021

Hello, works great thanks a lot!
I was wondering if anyone knew a way to detect if a message is a reply and then get the message it is a reply to?

sorry for very late reply, i just saw the comment by now
discord.js has Message#reference, in the property you can get message id of the message is replying to

@miichaaael
Copy link

miichaaael commented May 3, 2021

bang, extendedMessagenya taro dmn ?
folder event atau folder handler ?

@TheArmagan
Copy link

TheArmagan commented May 17, 2021

can you add typings for that?

@Allvaa
Copy link
Author

Allvaa commented May 18, 2021

can you add typings for that?

declare module "discord.js" {
    interface MessageMentionOptions {
        repliedUser?: boolean;
    }

    interface Message {
        inlineReply(
            content: APIMessageContentResolvable | (MessageOptions & { split?: false }) | MessageAdditions,
          ): Promise<Message>;
        inlineReply(options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
        inlineReply(options: MessageOptions): Promise<Message | Message[]>;
        inlineReply(content: StringResolvable, options: (MessageOptions & { split?: false }) | MessageAdditions): Promise<Message>;
        inlineReply(content: StringResolvable, options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
        inlineReply(content: StringResolvable, options: MessageOptions): Promise<Message | Message[]>;
    }
}

the parameter typings stolen from discord.js's source code

@johng3587
Copy link

johng3587 commented May 28, 2021

Uhm how do I install this?

@AustrAlienGH
Copy link

AustrAlienGH commented May 29, 2021

download the file, save it to your project directory and import it like any other package.

@MarsRon
Copy link

MarsRon commented Jun 16, 2021

can you add typings for that?

declare module "discord.js" {
    interface MessageMentionOptions {
        repliedUser?: boolean;
    }

    interface Message {
        inlineReply(
            content: APIMessageContentResolvable | (MessageOptions & { split?: false }) | MessageAdditions,
          ): Promise<Message>;
        inlineReply(options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
        inlineReply(options: MessageOptions): Promise<Message | Message[]>;
        inlineReply(content: StringResolvable, options: (MessageOptions & { split?: false }) | MessageAdditions): Promise<Message>;
        inlineReply(content: StringResolvable, options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
        inlineReply(content: StringResolvable, options: MessageOptions): Promise<Message | Message[]>;
    }
}

the parameter typings stolen from discord.js's source code

How do we use the typings?

@Allvaa
Copy link
Author

Allvaa commented Jun 17, 2021

can you add typings for that?

declare module "discord.js" {
    interface MessageMentionOptions {
        repliedUser?: boolean;
    }

    interface Message {
        inlineReply(
            content: APIMessageContentResolvable | (MessageOptions & { split?: false }) | MessageAdditions,
          ): Promise<Message>;
        inlineReply(options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
        inlineReply(options: MessageOptions): Promise<Message | Message[]>;
        inlineReply(content: StringResolvable, options: (MessageOptions & { split?: false }) | MessageAdditions): Promise<Message>;
        inlineReply(content: StringResolvable, options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
        inlineReply(content: StringResolvable, options: MessageOptions): Promise<Message | Message[]>;
    }
}

the parameter typings stolen from discord.js's source code

How do we use the typings?

put it in your custom typings directory

@qrvd
Copy link

qrvd commented Jun 20, 2021

could you add a license?

@firminsurgithub
Copy link

firminsurgithub commented Jul 8, 2021

LOL
image

@AKASGaming
Copy link

AKASGaming commented Jul 10, 2021

LOL
image

I'm getting the same message in v12, any luck on fixing it?

@nitplayz
Copy link

nitplayz commented Jul 14, 2021

Suggestion! Make it so the bots turn 'mention off', I know this is possible cuz Dank Memer haves it, Other than that, thank you very much!

just add { allowedMentions: { repliedUser: false } } in the second parameter like

msg.inlineReply("yo", { allowedMentions: { repliedUser: false } });
// or if you wanna send embed
msg.inlineReply({
  embed: yourembed,
  allowedMentions: { repliedUser: false }
});

or you can make it default by changing the true to false in
https://gist.github.com/Allvaa/0320f06ee793dc88e4e209d3ea9f6256#file-extendedmessage-js-L5

hi sir how can i send embed messages using this bot as it is working perfectly and giving replies to each command

@Allvaa
Copy link
Author

Allvaa commented Jul 14, 2021

LOL
image

LOL
image

I'm getting the same message in v12, any luck on fixing it?

hm can i see how do you use it?

@Allvaa
Copy link
Author

Allvaa commented Jul 14, 2021

Suggestion! Make it so the bots turn 'mention off', I know this is possible cuz Dank Memer haves it, Other than that, thank you very much!

just add { allowedMentions: { repliedUser: false } } in the second parameter like

msg.inlineReply("yo", { allowedMentions: { repliedUser: false } });
// or if you wanna send embed
msg.inlineReply({
  embed: yourembed,
  allowedMentions: { repliedUser: false }
});

or you can make it default by changing the true to false in
https://gist.github.com/Allvaa/0320f06ee793dc88e4e209d3ea9f6256#file-extendedmessage-js-L5

hi sir how can i send embed messages using this bot as it is working perfectly and giving replies to each command

you just saw it

@firminsurgithub
Copy link

firminsurgithub commented Jul 15, 2021

LOL
image

LOL
image

I'm getting the same message in v12, any luck on fixing it?

hm can i see how do you use it?

no, is just that i use discord-buttons and i am little bit stupid

@Allvaa
Copy link
Author

Allvaa commented Jul 15, 2021

LOL
image

LOL
image

I'm getting the same message in v12, any luck on fixing it?

hm can i see how do you use it?

no, is just that i use discord-buttons and i am little bit stupid

i see, another extension seems to broke it

@AKASGaming
Copy link

AKASGaming commented Jul 15, 2021

LOL
image

LOL
image

I'm getting the same message in v12, any luck on fixing it?

hm can i see how do you use it?

no, is just that i use discord-buttons and i am little bit stupid

i see, another extension seems to broke it

Same here, was using discord-buttons

@JesseBS2
Copy link

JesseBS2 commented Jul 26, 2021

You're absolutely awesome. Thank you

@AKASGaming
Copy link

AKASGaming commented Aug 7, 2021

Version 13 please

you don't need a v13 version, v13 already does this

@Allvaa
Copy link
Author

Allvaa commented Aug 8, 2021

Version 13 please

you don't need a v13 version, v13 already does this

yeah

@RadioEnthusiast
Copy link

RadioEnthusiast commented Nov 19, 2021

When I try to use an embed and buttons, the bot responds with [object Object]. How can I fix this?

Code:

  if (command === 'discord') {
  if (!message.content.startsWith(prefix)) return;
    message.lineReply(discordEmbed, discordButton);
  } 

@Allvaa
Copy link
Author

Allvaa commented Nov 25, 2021

When I try to use an embed and buttons, the bot responds with [object Object]. How can I fix this?

Code:

  if (command === 'discord') {
  if (!message.content.startsWith(prefix)) return;
    message.lineReply(discordEmbed, discordButton);
  } 

thats not how to send the message. also use discord.js v13, so you wont need the code snippet anymore

@Gomez0015
Copy link

Gomez0015 commented Jan 18, 2022

Bug: when replying to a reply the bot displays a SERVER tag next to the user, how can I fix that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment