Foundry and discord bot
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m51s

This commit is contained in:
2026-10-11 22:26:29 +02:00
parent a2b512699a
commit 1402045001
65 changed files with 5962 additions and 144 deletions

View File

@@ -0,0 +1,44 @@
const { REST, Routes } = require('discord.js');
const { getConfig } = require('./config');
const commands = require('./commands');
// Global by default: the bot can be invited to any number of servers, and the
// campaign it answers with is decided per server by Dragonroll.
// Pass "--guild <server id>" while developing to see changes in one server at once.
function routeFor(clientId, guildId) {
return guildId
? Routes.applicationGuildCommands(clientId, guildId)
: Routes.applicationCommands(clientId);
}
function parseGuildArg(argv) {
const index = argv.indexOf('--guild');
if (index === -1) return null;
const guildId = argv[index + 1];
if (!guildId || guildId.startsWith('--')) {
throw new Error('Usage: npm run deploy-commands -- --guild <discord server id>');
}
return guildId;
}
async function deploy() {
const config = getConfig();
const guildId = parseGuildArg(process.argv.slice(2));
const rest = new REST({ version: '10' }).setToken(config.discordToken);
await rest.put(routeFor(config.discordClientId, guildId), { body: commands.map((command) => command.toJSON()) });
if (guildId) {
console.log(`Registered ${commands.length} commands in Discord server ${guildId}.`);
return;
}
console.log(`Registered ${commands.length} commands globally.`);
console.log('New servers can take up to an hour to see them; the bot also registers them when it joins a server.');
}
deploy().catch((error) => {
console.error('Could not register Discord commands:', error.message);
process.exitCode = 1;
});