Initial commit

This commit is contained in:
2024-08-09 16:56:18 +00:00
commit af7628aaf1
22 changed files with 1334 additions and 0 deletions

26
init/register-commands.ts Normal file
View File

@@ -0,0 +1,26 @@
import {REST, Routes} from 'discord.js';
import {config} from '../config';
import {logger} from '../logger';
function isArray<T>(data: unknown): data is Array<T>{
return (data as Array<T>).length !== undefined;
}
export async function registerCommands(commands: Array<string>): Promise<number>{
const rest = new REST().setToken(config.token);
try{
const data = await rest.put(
Routes.applicationCommands(config.clientId),
{body: commands},
);
if(!isArray(data)) throw Error('Type error');
return data.length;
}catch(err: unknown){
let message;
if(err instanceof Error) message = err.message;
else message = String(message);
logger.error(`While executing "registerCommands", ${message}`);
return -1;
}
}