Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Discord.js v12 Inline Replies (use discord.js's Message#reply instead because the PR has been merged)
const { APIMessage, Structures } = require("discord.js");
class Message extends Structures.get("Message") {
async inlineReply(content, options) {
const mentionRepliedUser = typeof ((options || content || {}).allowedMentions || {}).repliedUser === "undefined" ? true : ((options || content).allowedMentions).repliedUser;
delete ((options || content || {}).allowedMentions || {}).repliedUser;
const apiMessage = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this.channel, content, options).resolveData();
Object.assign(apiMessage.data, { message_reference: { message_id: this.id } });
if (!apiMessage.data.allowed_mentions || Object.keys(apiMessage.data.allowed_mentions).length === 0)
apiMessage.data.allowed_mentions = { parse: ["users", "roles", "everyone"] };
if (typeof apiMessage.data.allowed_mentions.replied_user === "undefined")
Object.assign(apiMessage.data.allowed_mentions, { replied_user: mentionRepliedUser });
if (Array.isArray(apiMessage.data.content)) {
return Promise.all(apiMessage.split().map(x => {
x.data.allowed_mentions = apiMessage.data.allowed_mentions;
return x;
}).map(this.inlineReply.bind(this)));
}
const { data, files } = await apiMessage.resolveFiles();
return this.client.api.channels[this.channel.id].messages
.post({ data, files })
.then(d => this.client.actions.MessageCreate.handle(d).message);
}
}
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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment