mirror of
https://github.com/gizmo4487/O-Bot.git
synced 2026-07-14 00:25:54 -05:00
Formatting changes + Update version to 1.0.0
This commit is contained in:
25
o-bot.js
25
o-bot.js
@@ -1,5 +1,4 @@
|
||||
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
||||
const fetch = require('node-fetch');
|
||||
const { Client, Collection, Events, GatewayIntentBits, MessageFlags } = require('discord.js');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
@@ -9,7 +8,7 @@ const bot = new Client({
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildVoiceStates,
|
||||
],
|
||||
autoReconnect:true,
|
||||
autoReconnect: true,
|
||||
});
|
||||
|
||||
bot.commands = new Collection();
|
||||
@@ -17,13 +16,13 @@ bot.commands = new Collection();
|
||||
const cmdFoldersPath = path.join(__dirname, 'cmd');
|
||||
const cmdFolders = fs.readdirSync(cmdFoldersPath);
|
||||
|
||||
for(const folder of cmdFolders) {
|
||||
for (const folder of cmdFolders) {
|
||||
const cmdPath = path.join(cmdFoldersPath, folder);
|
||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith('.js'));
|
||||
for(const file of cmdFiles) {
|
||||
for (const file of cmdFiles) {
|
||||
const filePath = path.join(cmdPath, file);
|
||||
const cmd = require(filePath);
|
||||
if('data' in cmd && 'execute' in cmd) {
|
||||
if ('data' in cmd && 'execute' in cmd) {
|
||||
console.log('Adding command: ' + cmd.data.name);
|
||||
bot.commands.set(cmd.data.name, cmd);
|
||||
}
|
||||
@@ -35,25 +34,25 @@ for(const folder of cmdFolders) {
|
||||
// End slash command setup
|
||||
// Display console message when logged in
|
||||
bot.once('ready', () => {
|
||||
console.log('O-Bot is ready!');
|
||||
console.log('O-Bot is ready!');
|
||||
});
|
||||
|
||||
// Reconnecting
|
||||
bot.on("reconnecting", () => {
|
||||
console.log("Reconnecting!");
|
||||
});
|
||||
});
|
||||
|
||||
// Resume
|
||||
bot.on("resume", () => {
|
||||
console.log("Connection restored!");
|
||||
});
|
||||
});
|
||||
|
||||
// Handle slash commands
|
||||
bot.on(Events.InteractionCreate, async interaction => {
|
||||
if(!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const cmd = interaction.client.commands.get(interaction.commandName);
|
||||
if(!cmd) {
|
||||
if (!cmd) {
|
||||
console.error('No matching command ' + interaction.commandName + ' was found!');
|
||||
return;
|
||||
}
|
||||
@@ -61,10 +60,10 @@ bot.on(Events.InteractionCreate, async interaction => {
|
||||
try {
|
||||
await cmd.execute(interaction);
|
||||
}
|
||||
catch(error) {
|
||||
catch (error) {
|
||||
const errorMsg = `Uh-oh...something went wrong. Try again later!`;
|
||||
console.error(error);
|
||||
if(interaction.replied || interaction.deferred) {
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({
|
||||
content: errorMsg,
|
||||
flags: MessageFlags.Ephemeral
|
||||
|
||||
Reference in New Issue
Block a user