Files
DiscordKeyBot/register.js

88 lines
2.1 KiB
JavaScript

import 'dotenv/config';
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',
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
}
]
},
{
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
}
]
}
]
}
];
const rest = new REST({ version: '10' }).setToken(TOKEN);
(async () => {
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);
}
})();