Table of contents
About
discord.js-embed-menu is a Node.js module based on discord.js-menu that allows you to easily create reaction embeds menu using
discord.js.
- Channel and direct message menu
- Remove other users reactions
- Pagination system
- Mention user
- Timeout and auto delete
Installation
Node.js 14.0.0 or newer is required.
npm i discord.js-embed-menu --save
Example usage
import { Client, MessageEmbed } from 'discord.js';
import { DiscordEmbedMenu } from 'discord.js-embed-menu';
const client = new Client();
client.on('message', message => {
if (message.content === '!menu') {
let menu = new DiscordEmbedMenu(message.channel, message.author, [
{
name: 'main',
content: new MessageEmbed({
title: 'Main menu',
description: 'Please chose an action',
fields: [
{
name: "📝 Sub menu",
value: "Goes to another menu.",
inline: false
},
{
name: "✉️ Direct message",
value: "Sends a direct message.",
inline: false
},
{
name: "❌ Close",
value: "Close the menu.",
inline: false
}
]
}),
reactions: {
'📝': 'sub-menu',
'✉️': async (menu) => {
menu.user.send(`Hello dear ${menu.user.username}.`);
},
'❌': 'delete'
}
},
{
name: 'sub-menu',
content: new MessageEmbed({
title: 'Sub menu',
description: 'This is another page.',
fields: [
{
name: "⬅️ Back",
value: "Go backwards.",
inline: false
},
{
name: "❌ Close",
value: "Close the menu.",
inline: false
}
]
}),
reactions: {
'⬅️': 'main',
'❌': 'delete'
}
}
]);
menu.start();
menu.on('page-changing', (oldPageIndex, oldPage, newPageIndex, newPage) => {
console.log(`Menu is going from "${oldPage.content.title}" (${oldPageIndex}) to "${newPage.content.title}" (${newPageIndex})`);
});
menu.on('page-changed', (pageIndex, page) => {
console.log(`Menu is now on "${page.content.title}" (${pageIndex})`);
});
}
});
client.login("Get your bot's oauth token at https://discord.com/developers/applications");
Special Destinations
Discord.js-embed-menu comes with 6 pre-defined destinations with specific uses.
Destination | Function |
---|
first | Goes to the first page in the array. |
last | Goes to the last page in the array. |
previous | Goes to the previous page in the array. |
next | Goes to the next page in the array. |
stop | Removes reactions from the embed and stops updating the menu. |
delete | Stops the menu and deletes the message. |
Calling a page one of these wouldn't work, it prioritizes special destinations.
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested.
Links