Discord.js Slash Command & Event Handler
NodeJS 16.6.0 Or Higher
Install The Project Node Dependencies
npm install
Fill out the config.js
const { Intents } = require("discord.js");
const config = {
bot: {
token: "", // Your discord bot token, you must have authorized the bot with the application.commands scope in order to use slash commands
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS], // You can find the available intents on https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS
guildId: "", // Update this field to only register commands a guild, this will make the commands to load instantly in the selected gulld (Optional)
},
};
module.exports = config;
Note: There are some examples of usage in the commands
and events
folder inside the src
folder.
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("command-name") // /command-name
.setDescription("command description"),
run: async (interaction) => {
// code to run
},
};
module.exports = {
event: "event-name", // Name of the event e.g. 'ready'
oneTime: false, // If set to true the event will only be fired once until the client is restarted
run: async (i) => {
// code to run
},
};
This is everything you need to know! Have a good one :)