Skip to content

Instantly share code, notes, and snippets.

@Alespren
Forked from Allvaa/ExtendedMessage.js
Last active April 30, 2021 15:50
Show Gist options
  • Save Alespren/92b30ba008bb080879ff07ee78c01f6a to your computer and use it in GitHub Desktop.
Save Alespren/92b30ba008bb080879ff07ee78c01f6a to your computer and use it in GitHub Desktop.
Discord.js v12 Inline Replies w/ Default Mention Settings
const { APIMessage, Structures } = require("discord.js");
class ExtAPIMessage extends APIMessage {
resolveData() {
if (this.data) return this;
super.resolveData();
if ((this.options.allowedMentions || {}).repliedUser !== undefined) {
if (this.data.allowed_mentions === undefined) this.data.allowed_mentions = {};
Object.assign(this.data.allowed_mentions, { replied_user: this.options.allowedMentions.repliedUser });
delete this.options.allowedMentions.repliedUser;
} else {
// Changing replied_user to true will turn mentions on by default
this.data.allowed_mentions = { replied_user: false }
}
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();
client.on("message", msg => {
if (msg.author.bot) return;
if (msg.content === "hi") {
msg.inlineReply("hello");
}
});
client.login("ur token");
@Alespren
Copy link
Author

If you want to change whether the author is pinged by DEFAULT change the 'false' on line 13 to 'true'

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