TheOchulus/index.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-11-17 00:32:16 +01:00
// Require the necessary discord.js classes
2023-11-20 00:59:41 +01:00
import fs from 'node:fs';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { fileURLToPath } from 'url';
import { Client, Collection, GatewayIntentBits } from 'discord.js';
import { config } from 'dotenv';
config();
2023-11-17 00:32:16 +01:00
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
2023-11-18 00:23:51 +01:00
client.commands = new Collection();
2023-11-18 21:27:42 +01:00
client.cooldowns = new Collection();
2023-11-18 00:23:51 +01:00
2023-11-20 00:59:41 +01:00
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
2023-11-18 00:23:51 +01:00
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
2023-11-20 00:59:41 +01:00
const command = await import(pathToFileURL(filePath));
2023-11-18 00:23:51 +01:00
// Set a new item in the collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
2023-11-18 00:28:36 +01:00
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
2023-11-18 00:23:51 +01:00
}
}
}
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
2023-11-18 00:23:51 +01:00
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
2023-11-20 00:59:41 +01:00
const event = await import(pathToFileURL(filePath));
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
2023-11-18 00:23:51 +01:00
}
}
2023-11-17 00:32:16 +01:00
2023-11-20 00:59:41 +01:00
fetch(
`https://id.twitch.tv/oauth2/token?client_id=${process.env.igdbClientId}&client_secret=${process.env.igdbClientSecret}&grant_type=client_credentials`,
{
method: 'POST',
},
)
.then(r => r.json().then(data => ({ status: r.status, headers: r.headers, body: data })))
.then(resp => {
if (resp.status != 200) {
console.log('Failed with ', resp.status, resp.body);
return;
}
console.log(resp.body.access_token);
})
.catch(err => {
console.error(err);
})
.finally();
client.login(process.env.token);