npm install maclary discord.js
yarn add maclary discord.js
pnpm add maclary discord.js
Maclary is a Discord bot framework intended to make developing bots a lot faster and easier, with built in command, event and component handling.
It is named after Hairy Maclary, a character from the New Zealand childrens book series of the same name.
Maclary is still in its early stages, please report any bugs you may find.
Better documentation and guides coming soon!
Maclary requires Discord.js v14 to work, which is currently in development (npm install discord.js@dev
).
It is very important that you include the main
field within your package.json.
src/index.js
process.env.NODE_ENV = 'development'; // IMPORTANT!
const { MaclaryClient } = require('maclary');
const { Partials } = require('discord.js');
const client = new MaclaryClient({
intents: ['Guilds', 'GuildMessages', 'DirectMessages', 'MessageContent'],
partials: [Partials.Channel],
defaultPrefix: '!',
developmentPrefix: 'dev!',
developmentGuildId: '123456789012345678',
});
const token = process.env.BOT_TOKEN;
client.login(token);
src/commands/echo.js
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const { Command, Preconditions } = require('maclary');
const actionRow = new ActionRowBuilder().addComponents([
new ButtonBuilder().setStyle(ButtonStyle.Primary).setLabel('Ping Me!'),
]);
module.exports = class ChatInputEcho extends Command {
constructor() {
super({
type: Command.Type.ChatInput,
kinds: [Command.Kind.Slash, Command.Kind.Prefix],
preconditions: [Preconditions.GuildOnly],
name: 'echo',
description: 'Echos the input.',
aliases: ['say'],
options: [
{
type: Command.OptionType.String,
name: 'input',
description: 'The text to echo.',
},
],
});
}
async onMessage(message, args) {
const content = args.rest();
actionRow.components[0].setCustomId(`pingUser,${message.author.id}`);
await message.reply({ content, components: [actionRow] });
}
async onChatInput(interaction) {
const content = interaction.options.getString('input');
actionRow.components[0].setCustomId(`pingUser,${interaction.user.id}`);
await interaction.reply({ content, components: [actionRow] });
}
};
src/components/pingUser.js
const { Component } = require('maclary');
module.exports = class PingUser extends Component {
constructor() {
super({ id: 'pingUser' });
}
async onButton(button) {
const [, userId] = button.customId.split(',');
const user = await this.container.client.users.fetch(userId);
await button.reply(user.toString());
}
};
And that is it! Maclary will handle the rest.
You can set the categories for commands by placing them in a folder that starts with @
.
For example, commands/@moderator/kick.js
.
Maclary allows you to create subcommands using folders that start with !
.
For example, commands/!sub/command.js
, commands/!sub/command/group.js
, commands/@category/!sub/command.js
.
Whenever you restart your bot, Maclary will compare your local application commands with the ones on Discord. If there are any differences, Maclary will automatically update your commands, otherwise skip.
This will help in preventing you from reaching Discords global rate limit of 200 application command creates per day, per guild.
The already made plugins will become available soon, when documentation is created for them.