Skip to content
Snippets Groups Projects
Commit d73437f7 authored by Patric Plattner's avatar Patric Plattner
Browse files

First working version of role distribution.

parent a30180de
No related branches found
No related tags found
No related merge requests found
{
"name": "finf-discord",
"version": "0.1.0",
"description": "",
"main": "index.ts",
"scripts": {
"dev": "node index.js"
},
"repository": {
"type": "git",
"url": "git@git.finf.uni-hannover.de:Yashin/finf-discord-js.git"
},
"keywords": [],
"author": "",
"license": "GPLv3",
"dependencies": {
"@discordjs/rest": "^0.1.0-canary.0",
"@types/node": "^16.7.5",
"discord-api-types": "^0.22.0",
"discord.js": "^13.1.0",
"mongoose": "^6.0.2",
"typescript": "^4.4.2"
}
}
const {REST} = require('@discordjs/rest');
const {Routes} = require('discord-api-types/v9');
const {Client, Intents} = require('discord.js');
const fs = require('fs');
const botConfig = {
token: process.env.DISCORD_API_TOKEN,
applicationID: process.env.DISCORD_APP_ID
};
// Loading discord client to get all guild IDs
const client = new Client({intents: [Intents.FLAGS.GUILDS]});
client.on('ready', () => {
// Getting all command Javascript files from the commands folder
commands = []
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command);
}
const rest = new REST({version: '9'}).setToken(botConfig.token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
const guildIDs = await client.guilds.cache.map(guild => guild.id);
console.log(guildIDs)
//Going through all guildIDs and registering the commands with each one.
await Promise.all(guildIDs.map(async (guildID) => {
console.log(guildID);
await rest.put(
Routes.applicationGuildCommands(botConfig.applicationID, guildID),
{body: commands},
);
}));
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
});
client.login(botConfig.token);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment