From 570e94dd489537459d5d140d369999ba7926555f Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 17 Sep 2024 11:03:13 +0200 Subject: [PATCH] Better typeguard (#162) --- src/commands/music/lyrics.ts | 8 ++++---- src/events/message/messageCreate.ts | 11 ++--------- src/events/player/playerStart.ts | 4 ++-- src/utils/reminder.ts | 4 ++-- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/commands/music/lyrics.ts b/src/commands/music/lyrics.ts index 10f549f..9369481 100644 --- a/src/commands/music/lyrics.ts +++ b/src/commands/music/lyrics.ts @@ -1,6 +1,6 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { Player, useMainPlayer, useQueue } from "discord-player"; -import { ChannelType, ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js"; +import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; @@ -131,12 +131,12 @@ export default { syncedLyrics?.onChange(async (lyrics) => { const content = `[${data[0].trackName}]: ${lyrics}`; - if (interaction.channel?.type === ChannelType.GroupDM) { - await interaction.followUp({ + if (interaction.channel?.isSendable()) { + await interaction.channel?.send({ content, }); } else { - await interaction.channel?.send({ + await interaction.followUp({ content, }); } diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index c9533e3..13892ef 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -1,11 +1,4 @@ -import { - ChannelType, - Client, - EmbedBuilder, - GuildMember, - Message, - TextBasedChannel, -} from "discord.js"; +import { Client, EmbedBuilder, GuildMember, Message, TextBasedChannel } from "discord.js"; import { getLocale } from "../../utils/locales"; import { isImage, userWithNickname } from "../../utils/misc"; import { showDate } from "../../utils/time"; @@ -172,7 +165,7 @@ export default async (message: Message, client: Client) => { !message.content.replace(new RegExp(regex, "g"), "").trim() && messages.length === urls.length && !message.mentions.repliedUser && - message.channel.type !== ChannelType.GroupDM + message.channel.isSendable() ) { message.delete(); return message.channel.send({ embeds: [embed] }); diff --git a/src/events/player/playerStart.ts b/src/events/player/playerStart.ts index 53448db..93e7fcc 100644 --- a/src/events/player/playerStart.ts +++ b/src/events/player/playerStart.ts @@ -1,6 +1,6 @@ import { EmbedBuilder } from "@discordjs/builders"; import { GuildQueue, Track } from "discord-player"; -import { ChannelType, Client } from "discord.js"; +import { Client } from "discord.js"; import { Metadata } from "../../utils/metadata"; import { emojiPng } from "../../utils/misc"; @@ -20,7 +20,7 @@ export default (queue: GuildQueue, track: Track, client: Client) => { iconURL: emojiPng("🎶"), }); - if (queue.metadata.channel?.type !== ChannelType.GroupDM) { + if (queue.metadata.channel?.isSendable()) { queue.metadata?.channel?.send({ embeds: [embed] }); } }; diff --git a/src/utils/reminder.ts b/src/utils/reminder.ts index c1a38ee..58b7f3d 100644 --- a/src/utils/reminder.ts +++ b/src/utils/reminder.ts @@ -1,4 +1,4 @@ -import { ChannelType, Client, Colors, EmbedBuilder, User } from "discord.js"; +import { Client, Colors, EmbedBuilder, User } from "discord.js"; import { getLocale } from "./locales"; import { cleanCodeBlock } from "./misc"; import { showDate, strToSeconds, timeDeltaToString } from "./time"; @@ -169,7 +169,7 @@ export const sendReminder = (client: Client, info: infoReminder, option: OptionR } else { // Channel client.channels.fetch(info.channelId ?? "").then((channel) => { - if (channel?.isTextBased() && channel.type !== ChannelType.GroupDM) { + if (channel?.isSendable()) { let content = `<@${info.userId}>`; embed.setFooter({ text: `${loc.get("c_reminder17")} ${timeDeltaToString(info.createdAt)}`,