Skip to content

Commit

Permalink
update deployCommands type
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Nov 13, 2023
1 parent f4ccb3d commit 5733526
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ export {
ButtonStyleTypes,
MessageComponentTypes,
} from 'discord-interactions'
export { ComponentType, TextInputStyle, ButtonStyle } from 'discord.js'
export {
ComponentType,
TextInputStyle,
ButtonStyle,
SlashCommandBuilder,
} from 'discord.js'
36 changes: 15 additions & 21 deletions src/lib/deployCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { REST, Routes, ApplicationCommandData } from 'discord.js'

import { REST, Routes } from 'discord.js'
import { SlashCommandBuilder } from 'discord.js'
/**
* Deploys application commands to a specific guild.
*
Expand All @@ -9,45 +9,39 @@ import { REST, Routes, ApplicationCommandData } from 'discord.js'
* @param {string} token - The token used for authentication with the Discord API.
* @param {string} discordClientId - The Discord client ID.
* @param {string} guildId - The ID of the guild where commands are being deployed.
* @param {ApplicationCommandData[]} commands - An array of ApplicationCommandData representing the commands to be deployed.
* @param { SlashCommandBuilder[]} commands - An array of SlashCommandBuilder representing the commands to be deployed.
* @returns {Promise<void>} A promise that resolves when commands are successfully deployed.
* @throws {Error} Will throw an error if there is a problem with the deployment.
*
* @example
* ```typescript
* import { config } from 'dotenv'
* config()
* const run = async () => {
* const token = process.env.DISCORD_TOKEN || ''
* const discordClientId = process.env.DISCORD_CLIENT_ID || ''
* const guildId = process.env.DISCORD_GUILD_ID || ''
* import { commands } from "./commands";
* import { deployCommands } from "@skeet-framework/discord-utils";
* import { DISCORD_APPLICATION_ID, DISCORD_GUILD_ID } from "../config";
*
* const commands = [
* {
* name: 'ping',
* description: 'Replies with pong',
* },
* ]
* const commandsData = Object.values(commands).map((command) => command.data);
*
* const run = async () => {
* const token = process.argv[2] || '';
* try {
* await deployCommands(token, discordClientId, guildId, commands)
* console.log('Commands deployed successfully.')
* await deployCommands(token, DISCORD_APPLICATION_ID, DISCORD_GUILD_ID, commandsData);
* console.log('Commands deployed successfully.');
* } catch (error) {
* console.error(`Error deploying commands: ${error}`)
* console.error(`Error deploying commands: ${error}`);
* }
* }
* };
*
* run()
* .then(() => console.log('Done'))
* .catch((error) => console.error(error))
* .catch((error) => console.error(error));
* ```
*/

export async function deployCommands(
token: string,
discordClientId: string,
guildId: string,
commands: ApplicationCommandData[],
commands: SlashCommandBuilder[],
): Promise<void> {
try {
console.log('Started refreshing application (/) commands.')
Expand Down

0 comments on commit 5733526

Please sign in to comment.