Added errorh andling, organized commands
This commit is contained in:
110
register.js
110
register.js
@ -3,62 +3,86 @@ import { REST, Routes } from 'discord.js';
|
||||
|
||||
const TOKEN = process.env.DISCORD_TOKEN;
|
||||
const CLIENT_ID = process.env.DISCORD_CLIENT_ID;
|
||||
const ADMIN_PERM = 0x00000008;
|
||||
|
||||
const commands = [
|
||||
{
|
||||
name: 'register',
|
||||
description: 'Send a registration message with a button'
|
||||
},
|
||||
{
|
||||
{
|
||||
name: 'register',
|
||||
description: 'Send a registration message with a button',
|
||||
default_member_permissions: ADMIN_PERM.toString()
|
||||
},
|
||||
{
|
||||
name: 'keys',
|
||||
description: 'Manage Steam keys',
|
||||
default_member_permissions: ADMIN_PERM.toString(),
|
||||
options: [
|
||||
{
|
||||
type: 1, // SUB_COMMAND
|
||||
name: 'load',
|
||||
description: 'Load a list of Steam keys from a file',
|
||||
options: [
|
||||
{
|
||||
name: 'file',
|
||||
description: 'Text file with one Steam key per line',
|
||||
type: 11, // Attachment
|
||||
required: true
|
||||
}
|
||||
{
|
||||
name: 'file',
|
||||
description: 'Text file with one Steam key per line',
|
||||
type: 11, // Attachment
|
||||
required: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'setlogging',
|
||||
},
|
||||
{
|
||||
type: 1, // SUB_COMMAND
|
||||
name: 'get',
|
||||
description: 'Get a user\'s registered Steam key',
|
||||
options: [
|
||||
{
|
||||
name: 'user',
|
||||
description: 'User to look up',
|
||||
type: 6, // USER type
|
||||
required: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 1, // SUB_COMMAND
|
||||
name: 'check',
|
||||
description: 'Check how many keys are left'
|
||||
},
|
||||
{
|
||||
type: 1, // SUB_COMMAND
|
||||
name: 'logging',
|
||||
description: 'Set the logging channel for key warnings',
|
||||
options: [
|
||||
{
|
||||
name: 'channel',
|
||||
description: 'Channel to send logging messages to',
|
||||
type: 7, // Channel
|
||||
required: true
|
||||
}
|
||||
{
|
||||
name: 'channel',
|
||||
description: 'Channel to send logging messages to',
|
||||
type: 7, // Channel
|
||||
required: true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(TOKEN);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// Fetch all current global commands
|
||||
const currentCommands = await rest.get(
|
||||
Routes.applicationCommands(CLIENT_ID)
|
||||
);
|
||||
|
||||
// Delete each existing command
|
||||
for (const cmd of currentCommands) {
|
||||
await rest.delete(
|
||||
Routes.applicationCommand(CLIENT_ID, cmd.id)
|
||||
);
|
||||
console.log(`Deleted command: ${cmd.name}`);
|
||||
}
|
||||
|
||||
// Register new commands
|
||||
await rest.put(
|
||||
Routes.applicationCommands(CLIENT_ID),
|
||||
{ body: commands }
|
||||
);
|
||||
console.log('Global slash commands registered.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
try {
|
||||
const currentCommands = await rest.get(
|
||||
Routes.applicationCommands(CLIENT_ID)
|
||||
);
|
||||
for (const cmd of currentCommands) {
|
||||
await rest.delete(
|
||||
Routes.applicationCommand(CLIENT_ID, cmd.id)
|
||||
);
|
||||
console.log(`Deleted command: ${cmd.name}`);
|
||||
}
|
||||
await rest.put(
|
||||
Routes.applicationCommands(CLIENT_ID),
|
||||
{ body: commands }
|
||||
);
|
||||
console.log('Global slash commands registered.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user