discord slash commands base
This commit is contained in:
41
dist/discord.js
vendored
Normal file
41
dist/discord.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registerCommands = void 0;
|
||||
const rest_1 = require("@discordjs/rest");
|
||||
const v9_1 = require("discord-api-types/v9");
|
||||
const commands = [{
|
||||
name: 'queue',
|
||||
description: 'creates a queue'
|
||||
}];
|
||||
/**
|
||||
* register/reload commands on guild(s)
|
||||
* @param token discord bot token
|
||||
* @param clientId discord bot client id
|
||||
* @param guildIds discord guild id(s)
|
||||
*/
|
||||
function registerCommands(token, clientId, guildIds) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const rest = new rest_1.REST({ version: '9' }).setToken(token);
|
||||
if (typeof guildIds === 'string')
|
||||
guildIds = [guildIds];
|
||||
for (let i = 0; i < guildIds.length; i++) {
|
||||
try {
|
||||
yield rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
|
||||
console.log(`[${guildIds[i]}] registered command`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.registerCommands = registerCommands;
|
||||
34
src/discord.ts
Normal file
34
src/discord.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v9';
|
||||
|
||||
const commands = [{
|
||||
name: 'queue',
|
||||
description: 'creates a queue'
|
||||
}];
|
||||
|
||||
/**
|
||||
* register/reload commands on guild(s)
|
||||
* @param token discord bot token
|
||||
* @param clientId discord bot client id
|
||||
* @param guildIds discord guild id(s)
|
||||
*/
|
||||
export async function registerCommands(token: string, clientId: string, guildIds: string|string[]) {
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
if (typeof guildIds === 'string')
|
||||
guildIds = [guildIds];
|
||||
|
||||
for (let i = 0; i < guildIds.length; i++) {
|
||||
try {
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildIds[i]),
|
||||
{ body: commands },
|
||||
);
|
||||
console.log(`[${guildIds[i]}] registered command`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user