diff --git a/src/commands/config/Language.ts b/src/commands/config/Language.ts index 68d63bf46..ede0f2c6d 100644 --- a/src/commands/config/Language.ts +++ b/src/commands/config/Language.ts @@ -1,5 +1,6 @@ import { Command, type Context, type Lavamusic } from "../../structures/index.js"; import { Language, LocaleFlags } from "../../types.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class LanguageCommand extends Command { constructor(client: Lavamusic) { @@ -131,19 +132,16 @@ export default class LanguageCommand extends Command { } } - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); - // Fetch all available languages const languages = Object.values(Language).map((language) => ({ name: language, value: language, })); - // Filter languages based on the focused value const filtered = languages.filter((language) => language.name.toLowerCase().includes(focusedValue.toLowerCase())); - // Respond with the filtered language options await interaction.respond(filtered.slice(0, 25)).catch(console.error); } } diff --git a/src/commands/music/Play.ts b/src/commands/music/Play.ts index ee09e477f..208aa8d80 100644 --- a/src/commands/music/Play.ts +++ b/src/commands/music/Play.ts @@ -1,5 +1,6 @@ import { LoadType } from "shoukaku"; import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class Play extends Command { constructor(client: Lavamusic) { @@ -165,7 +166,7 @@ export default class Play extends Command { } } - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); try { diff --git a/src/commands/music/PlayNext.ts b/src/commands/music/PlayNext.ts index 3c8a9538b..9d4e0ad5e 100644 --- a/src/commands/music/PlayNext.ts +++ b/src/commands/music/PlayNext.ts @@ -1,5 +1,6 @@ import { LoadType } from "shoukaku"; import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class PlayNext extends Command { constructor(client: Lavamusic) { @@ -153,10 +154,9 @@ export default class PlayNext extends Command { } } - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); - // Search for songs based on the focused value const res = await this.client.queue.search(focusedValue); const songs = []; @@ -169,7 +169,6 @@ export default class PlayNext extends Command { }); } - // Respond with the song suggestions await interaction.respond(songs).catch(console.error); } } diff --git a/src/commands/playlist/AddSong.ts b/src/commands/playlist/AddSong.ts index 12a50b8d8..bbf9eb476 100644 --- a/src/commands/playlist/AddSong.ts +++ b/src/commands/playlist/AddSong.ts @@ -1,5 +1,6 @@ import { LoadType } from "shoukaku"; import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class AddSong extends Command { constructor(client: Lavamusic) { @@ -108,15 +109,12 @@ export default class AddSong extends Command { await ctx.sendMessage({ embeds: [successMessage] }); } - // Add autocomplete handler - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); const userId = interaction.user.id; - // Fetch user playlists from the database const playlists = await this.client.db.getUserPlaylists(userId); - // Filter playlists based on the focused value and respond const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase())); await interaction.respond( diff --git a/src/commands/playlist/Delete.ts b/src/commands/playlist/Delete.ts index d7a596eb0..02d94946a 100644 --- a/src/commands/playlist/Delete.ts +++ b/src/commands/playlist/Delete.ts @@ -1,4 +1,5 @@ import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class DeletePlaylist extends Command { constructor(client: Lavamusic) { @@ -66,15 +67,12 @@ export default class DeletePlaylist extends Command { }); } - // Add autocomplete handler - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); const userId = interaction.user.id; - // Fetch user playlists from the database const playlists = await this.client.db.getUserPlaylists(userId); - // Filter playlists based on the focused value and respond const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase())); await interaction.respond( diff --git a/src/commands/playlist/List.ts b/src/commands/playlist/List.ts index 8310a04d4..eeba5c708 100644 --- a/src/commands/playlist/List.ts +++ b/src/commands/playlist/List.ts @@ -30,7 +30,7 @@ export default class GetPlaylists extends Command { { name: "user", description: "cmd.list.options.user", - type: 6, // USER type + type: 6, required: false, }, ], diff --git a/src/commands/playlist/Load.ts b/src/commands/playlist/Load.ts index 7758ae8bd..4cc192e31 100644 --- a/src/commands/playlist/Load.ts +++ b/src/commands/playlist/Load.ts @@ -1,4 +1,5 @@ import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class LoadPlaylist extends Command { constructor(client: Lavamusic) { @@ -94,15 +95,12 @@ export default class LoadPlaylist extends Command { }); } - // Add autocomplete handler - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); const userId = interaction.user.id; - // Fetch user playlists from the database const playlists = await this.client.db.getUserPlaylists(userId); - // Filter playlists based on the focused value and respond const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase())); await interaction.respond( diff --git a/src/commands/playlist/RemoveSong.ts b/src/commands/playlist/RemoveSong.ts index 997962bf1..313ad1b2f 100644 --- a/src/commands/playlist/RemoveSong.ts +++ b/src/commands/playlist/RemoveSong.ts @@ -1,5 +1,6 @@ import { LoadType } from "shoukaku"; import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import type { AutocompleteInteraction } from "discord.js"; export default class RemoveSong extends Command { constructor(client: Lavamusic) { @@ -109,15 +110,12 @@ export default class RemoveSong extends Command { return await ctx.sendMessage({ embeds: [genericError] }); } } - // Add autocomplete handler - public async autocomplete(interaction) { + public async autocomplete(interaction: AutocompleteInteraction): Promise { const focusedValue = interaction.options.getFocused(); const userId = interaction.user.id; - // Fetch user playlists from the database const playlists = await this.client.db.getUserPlaylists(userId); - // Filter playlists based on the focused value and respond const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase())); await interaction.respond( diff --git a/src/commands/playlist/Steal.ts b/src/commands/playlist/Steal.ts index a8fa9f613..1f272e8f7 100644 --- a/src/commands/playlist/Steal.ts +++ b/src/commands/playlist/Steal.ts @@ -36,7 +36,7 @@ export default class StealPlaylist extends Command { { name: "user", description: "cmd.steal.options.user", - type: 6, // USER type + type: 6, required: true, }, ], @@ -129,17 +129,14 @@ export default class StealPlaylist extends Command { return; } - // Fetch the user object using the client const user = await interaction.client.users.fetch(userOptionId); if (!user) { await interaction.respond([{ name: "User not found.", value: "NoUserFound" }]).catch(console.error); - return; // Exit early if user cannot be found + return; } - // Proceed with fetching the user's playlists const playlists = await this.client.db.getUserPlaylists(user.id); - // If no playlists are found, respond accordingly if (!playlists || playlists.length === 0) { await interaction .respond([ @@ -149,13 +146,11 @@ export default class StealPlaylist extends Command { }, ]) .catch(console.error); - return; // Exit early as there are no playlists + return; } - // Filter playlists based on the focused value const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase())); - // Respond with filtered playlist names await interaction .respond( filtered.map((playlist) => ({ diff --git a/src/structures/Lavamusic.ts b/src/structures/Lavamusic.ts index 900e4e8ef..96a58dd27 100644 --- a/src/structures/Lavamusic.ts +++ b/src/structures/Lavamusic.ts @@ -35,8 +35,8 @@ export default class Lavamusic extends Client { public readonly emoji = config.emoji; public readonly color = config.color; private body: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; - public shoukaku: ShoukakuClient; - public topGG: Api; + public shoukaku!: ShoukakuClient; + public topGG!: Api; public utils = Utils; public queue = new Queue(this); @@ -56,8 +56,8 @@ export default class Lavamusic extends Client { loadPlugins(this); await this.login(token); - this.on(Events.InteractionCreate, async (interaction: Interaction<"cached">) => { - if (interaction.isButton()) { + this.on(Events.InteractionCreate, async (interaction: Interaction) => { + if (interaction.isButton() && interaction.guildId) { const setup = await this.db.getSetup(interaction.guildId); if (setup && interaction.channelId === setup.textId && interaction.message.id === setup.messageId) { this.emit("setupButtons", interaction); @@ -96,11 +96,12 @@ export default class Lavamusic extends Client { name_localizations: null, description_localizations: null, }; - // command description and name localizations + const localizations = []; i18n.getLocales().map((locale) => { localizations.push(localization(locale, command.name, command.description.content)); }); + for (const localization of localizations) { const [language, name] = localization.name; const [language2, description] = localization.description; @@ -114,14 +115,13 @@ export default class Lavamusic extends Client { }; } - // command options localizations if (command.options.length > 0) { command.options.map((option) => { - // command options name and description localizations const optionsLocalizations = []; i18n.getLocales().map((locale) => { optionsLocalizations.push(localization(locale, option.name, option.description)); }); + for (const localization of optionsLocalizations) { const [language, name] = localization.name; const [language2, description] = localization.description; @@ -134,19 +134,17 @@ export default class Lavamusic extends Client { [language2]: description, }; } - // command options description localization option.description = T(Locale.EnglishUS, option.description); }); - // subcommand options localizations data.options.map((option) => { if ("options" in option && option.options.length > 0) { option.options.map((subOption) => { - // subcommand options name and description localizations const subOptionsLocalizations = []; i18n.getLocales().map((locale) => { subOptionsLocalizations.push(localization(locale, subOption.name, subOption.description)); }); + for (const localization of subOptionsLocalizations) { const [language, name] = localization.name; const [language2, description] = localization.description; @@ -159,7 +157,6 @@ export default class Lavamusic extends Client { [language2]: description, }; } - // subcommand options description localization subOption.description = T(Locale.EnglishUS, subOption.description); }); } diff --git a/src/utils/BotLog.ts b/src/utils/BotLog.ts index 7481aa6b0..f72ae6c73 100644 --- a/src/utils/BotLog.ts +++ b/src/utils/BotLog.ts @@ -6,7 +6,7 @@ export default class BotLog { public static send(client: Lavamusic, message: string, type: "error" | "warn" | "info" | "success" = "info"): void { if (!client?.channels.cache && client.config.logChannelId) return; - const channel = client.channels.cache.get(client.config.logChannelId) as TextChannel; + const channel = client.channels.cache.get(client.config.logChannelId!) as TextChannel; if (!channel) return; const colors = { diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 8129df10e..67df5a200 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -17,7 +17,7 @@ export class Utils { public static updateStatus(client: Lavamusic, guildId?: string): void { const { user } = client; if (user && guildId === config.guildId) { - const player = client.queue.get(config.guildId); + const player = client.queue.get(config.guildId!); user.setPresence({ activities: [ { @@ -80,6 +80,7 @@ export class Utils { ctx.deferred ? ctx.interaction.followUp({ embeds: embed }) : ctx.interaction.reply({ embeds: embed }); return; } + (ctx.channel as TextChannel).send({ embeds: embed }); return; } @@ -117,11 +118,11 @@ export class Utils { const msgOptions = getButton(0); const msg = ctx.isInteraction ? await (ctx.deferred - ? ctx.interaction.followUp({ + ? ctx.interaction!.followUp({ ...msgOptions, fetchReply: true as boolean, }) - : ctx.interaction.reply({ ...msgOptions, fetchReply: true })) + : ctx.interaction!.reply({ ...msgOptions, fetchReply: true })) : await (ctx.channel as TextChannel).send({ ...msgOptions, fetchReply: true,