discord-bot-template/main.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-01-21 04:35:03 +00:00
/* eslint-disable no-case-declarations */
/* eslint-disable indent */
// dotenv for handling environment variables
const dotenv = require('dotenv');
dotenv.config();
2023-02-11 01:15:23 +00:00
const token = process.env.TOKEN;;
2023-01-21 04:35:03 +00:00
// Discord.JS
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel,
Partials.Message
],
});
// Various imports
const fn = require('./modules/functions.js');
const strings = require('./data/strings.json');
2023-02-11 01:15:23 +00:00
const isDev = process.env.DEBUG;
const statusChannelId = process.env.STATUSCHANNELID
2023-01-21 04:35:03 +00:00
client.once('ready', () => {
fn.collections.slashCommands(client);
console.log('Ready!');
client.channels.fetch(statusChannelId).then(channel => {
channel.send(`${new Date().toISOString()} -- Ready`);
});
});
// slash-commands
client.on('interactionCreate', async interaction => {
if (interaction.isCommand()) {
const { commandName } = interaction;
if (client.slashCommands.has(commandName)) {
client.slashCommands.get(commandName).execute(interaction);
} else {
interaction.reply('Sorry, I don\'t have access to that command.');
console.error('Slash command attempted to run but not found: /' + commandName);
}
}
});
client.login(token);