diff --git a/src/commands/coordinators/access.ts b/src/commands/coordinators/access.ts index b9b2528..dae91d4 100644 --- a/src/commands/coordinators/access.ts +++ b/src/commands/coordinators/access.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { ChannelType } from 'discord.js'; +import { ChannelType, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; export class AccessCommand extends Command { @@ -79,7 +79,7 @@ export class AccessCommand extends Command { if (!interaction.inCachedGuild()) { await interaction.reply({ content: 'This command can only be run in a server!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -94,7 +94,7 @@ export class AccessCommand extends Command { if (user === null && role === null) { await interaction.reply({ content: 'Error fetching slash command data!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -104,7 +104,7 @@ export class AccessCommand extends Command { await interaction.reply({ content: 'You have entered a user and a role at the same time! Please only enter one at a time.', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -116,7 +116,7 @@ export class AccessCommand extends Command { ) { await interaction.reply({ content: 'Please only select a text or voice channel!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -129,7 +129,7 @@ export class AccessCommand extends Command { ) { await interaction.reply({ content: 'Channel is not in ModMail/Private/Restricted category!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -143,7 +143,7 @@ export class AccessCommand extends Command { } else { await interaction.reply({ content: 'Could not find the role to edit permissions!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -185,7 +185,7 @@ export class AccessCommand extends Command { default: await interaction.reply({ content: 'Incorrect permission option!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -220,7 +220,7 @@ export class AccessCommand extends Command { default: await interaction.reply({ content: 'Incorrect permission option!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } diff --git a/src/commands/coordinators/clear.ts b/src/commands/coordinators/clear.ts index 12f009d..795f951 100644 --- a/src/commands/coordinators/clear.ts +++ b/src/commands/coordinators/clear.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Message } from 'discord.js'; +import { Message, MessageFlagsBitField } from 'discord.js'; export class ClearCommand extends Command { public constructor(context: Command.LoaderContext, options: Command.Options) { @@ -60,8 +60,8 @@ export class ClearCommand extends Command { if (channel === null || channel.isDMBased()) { await interaction.reply({ content: 'Could not fetch channel!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -70,8 +70,8 @@ export class ClearCommand extends Command { await interaction.reply({ content: `Successfully deleted ${messages} messages!`, - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); } diff --git a/src/commands/coordinators/private.ts b/src/commands/coordinators/private.ts index 521a771..0130e6e 100644 --- a/src/commands/coordinators/private.ts +++ b/src/commands/coordinators/private.ts @@ -19,7 +19,12 @@ import { RegisterBehavior } from '@sapphire/framework'; import { Subcommand } from '@sapphire/plugin-subcommands'; -import type { Guild, TextChannel, Snowflake } from 'discord.js'; +import { + Guild, + TextChannel, + Snowflake, + MessageFlagsBitField, +} from 'discord.js'; import { CategoryChannel, ChannelType, @@ -93,7 +98,9 @@ export class PrivateCommand extends Subcommand { const modUser = interaction.user; const { guild } = interaction; - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); // Checks if all the variables are of the right type if (guild === null) { @@ -235,7 +242,9 @@ export class PrivateCommand extends Subcommand { const modUser = interaction.user; const { guild, channel } = interaction; - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); // Checks if all the variables are of the right type if (guild === null || channel === null) { diff --git a/src/commands/economy/balance.ts b/src/commands/economy/balance.ts index 033b43b..e12571c 100644 --- a/src/commands/economy/balance.ts +++ b/src/commands/economy/balance.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import type { User, Guild, Message } from 'discord.js'; +import { User, Guild, Message, MessageFlagsBitField } from 'discord.js'; import { updateUser } from '#utils/database/dbExistingUser'; import { getBalance } from '#utils/database/fun/economy'; import { EmbedBuilder } from 'discord.js'; @@ -50,7 +50,7 @@ export class BalanceCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Could not find the guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -66,15 +66,9 @@ export class BalanceCommand extends Command { } public async messageRun(message: Message) { - const user = message.member?.user; + const user = message.author; const { guild } = message; - if (user === undefined) { - await message.react('❌'); - await message.reply('Could not find your user!'); - return; - } - if (guild === null) { await message.react('❌'); await message.reply('Could not find the guild!'); diff --git a/src/commands/economy/daily.ts b/src/commands/economy/daily.ts index 4e39ad7..c14b3ad 100644 --- a/src/commands/economy/daily.ts +++ b/src/commands/economy/daily.ts @@ -19,7 +19,13 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { Time } from '@sapphire/time-utilities'; -import type { User, Guild, GuildMember, Message } from 'discord.js'; +import { + User, + Guild, + GuildMember, + Message, + MessageFlagsBitField, +} from 'discord.js'; import { updateUser } from '#utils/database/dbExistingUser'; import { daily, getLastDaily } from '#utils/database/fun/economy'; import { EmbedBuilder } from 'discord.js'; @@ -51,7 +57,7 @@ export class DailyCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Could not find the guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -67,15 +73,9 @@ export class DailyCommand extends Command { } public async messageRun(message: Message) { - const user = message.member?.user; + const user = message.author; const { guild } = message; - if (user === undefined) { - await message.react('❌'); - await message.reply('Could not find your user!'); - return; - } - if (guild === null) { await message.react('❌'); await message.reply('Could not find the guild!'); diff --git a/src/commands/economy/pay.ts b/src/commands/economy/pay.ts index 3076f57..b4841c8 100644 --- a/src/commands/economy/pay.ts +++ b/src/commands/economy/pay.ts @@ -18,10 +18,10 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { User, Guild, Message } from 'discord.js'; +import { User, Guild, Message, MessageFlagsBitField } from 'discord.js'; import { updateUser } from '#utils/database/dbExistingUser'; import { getBalance, transfer } from '#utils/database/fun/economy'; -import { EmbedBuilder, TextChannel } from 'discord.js'; +import { EmbedBuilder } from 'discord.js'; import IDs from '#utils/ids'; export class BalanceCommand extends Command { @@ -75,7 +75,7 @@ export class BalanceCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Could not find the guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -117,15 +117,9 @@ export class BalanceCommand extends Command { return; } - const user = message.member?.user; + const user = message.author; const { guild } = message; - if (user === undefined) { - await message.react('❌'); - await message.reply('Could not find your user!'); - return; - } - if (guild === null) { await message.react('❌'); await message.reply('Could not find the guild!'); @@ -206,20 +200,28 @@ export class BalanceCommand extends Command { info.embeds.push(embed); // Log the payment in the server - let logChannel = guild.channels.cache.get(IDs.channels.logs.economy) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.economy); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch(IDs.channels.logs.economy)) as - | TextChannel - | undefined; - if (logChannel === undefined) { - this.container.logger.error('Pay Error: Could not fetch log channel'); + const fetchLogChannel = await guild.channels + .fetch(IDs.channels.logs.economy) + .catch(() => undefined); + + if (fetchLogChannel === null || fetchLogChannel === undefined) { + this.container.logger.error('Pay: Could not fetch log channel'); return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Pay: the bot does not have permission to send in the log channel', + ); + return info; + } + const logEmbed = new EmbedBuilder(embed.data); logEmbed.setTimestamp().setFooter({ text: `ID: ${user.id}` }); await logChannel.send({ embeds: [logEmbed] }); diff --git a/src/commands/fun/1984.ts b/src/commands/fun/1984.ts index b4e9b86..139b48d 100644 --- a/src/commands/fun/1984.ts +++ b/src/commands/fun/1984.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { N1984 } from '#utils/gifs'; import { addFunLog, countTotal } from '#utils/database/fun/fun'; @@ -50,8 +50,8 @@ export class N1984Command extends Command { // Type checks if (!(member instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -79,6 +79,6 @@ export class N1984Command extends Command { .setFooter({ text: embedFooter }); // Send the embed - await interaction.reply({ embeds: [n1984Embed], fetchReply: true }); + await interaction.reply({ embeds: [n1984Embed], withResponse: true }); } } diff --git a/src/commands/fun/cringe.ts b/src/commands/fun/cringe.ts index 1ac3701..5be1e7b 100644 --- a/src/commands/fun/cringe.ts +++ b/src/commands/fun/cringe.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Cringe } from '#utils/gifs'; import { addFunLog, countTotal } from '#utils/database/fun/fun'; @@ -49,8 +49,8 @@ export class CringeCommand extends Command { // Type check if (!(member instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -74,6 +74,6 @@ export class CringeCommand extends Command { .setFooter({ text: embedFooter }); // Send the embed - await interaction.reply({ embeds: [cringeEmbed], fetchReply: true }); + await interaction.reply({ embeds: [cringeEmbed], withResponse: true }); } } diff --git a/src/commands/fun/happy.ts b/src/commands/fun/happy.ts index c7c8d97..eafa307 100644 --- a/src/commands/fun/happy.ts +++ b/src/commands/fun/happy.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Happy } from '#utils/gifs'; export class HappyCommand extends Command { @@ -48,8 +48,8 @@ export class HappyCommand extends Command { // Type checks if (!(member instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -62,6 +62,6 @@ export class HappyCommand extends Command { .setImage(randomHappy); // Send the embed - await interaction.reply({ embeds: [happyEmbed], fetchReply: true }); + await interaction.reply({ embeds: [happyEmbed], withResponse: true }); } } diff --git a/src/commands/fun/hug.ts b/src/commands/fun/hug.ts index 53197eb..e11348a 100644 --- a/src/commands/fun/hug.ts +++ b/src/commands/fun/hug.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Hugs } from '#utils/gifs'; import { addFunLog, countTotal } from '#utils/database/fun/fun'; @@ -60,8 +60,8 @@ export class HugCommand extends Command { if (!(hugger instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -96,7 +96,7 @@ export class HugCommand extends Command { await interaction.reply({ content: `${user}`, embeds: [hugEmbed], - fetchReply: true, + withResponse: true, }); } } diff --git a/src/commands/fun/kill.ts b/src/commands/fun/kill.ts index e72a6e1..3f45d15 100644 --- a/src/commands/fun/kill.ts +++ b/src/commands/fun/kill.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Kill } from '#utils/gifs'; import { addFunLog, countTotal } from '#utils/database/fun/fun'; @@ -59,8 +59,8 @@ export class KillCommand extends Command { // Type checks if (!(sender instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -92,7 +92,7 @@ export class KillCommand extends Command { await interaction.reply({ content: `${user}`, embeds: [killEmbed], - fetchReply: true, + withResponse: true, }); } } diff --git a/src/commands/fun/poke.ts b/src/commands/fun/poke.ts index 9f97242..da14032 100644 --- a/src/commands/fun/poke.ts +++ b/src/commands/fun/poke.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Poke } from '#utils/gifs'; import { addFunLog, countTotal } from '#utils/database/fun/fun'; @@ -59,8 +59,8 @@ export class PokeCommand extends Command { // Type checks if (!(sender instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -95,7 +95,7 @@ export class PokeCommand extends Command { await interaction.reply({ content: `${user}`, embeds: [pokeEmbed], - fetchReply: true, + withResponse: true, }); } } diff --git a/src/commands/fun/sad.ts b/src/commands/fun/sad.ts index ee1986d..8c5aa96 100644 --- a/src/commands/fun/sad.ts +++ b/src/commands/fun/sad.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Sad } from '#utils/gifs'; export class SadCommand extends Command { @@ -48,8 +48,8 @@ export class SadCommand extends Command { // Type checks if (!(member instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -62,6 +62,6 @@ export class SadCommand extends Command { .setImage(randomSad); // Send the embed - await interaction.reply({ embeds: [sadEmbed], fetchReply: true }); + await interaction.reply({ embeds: [sadEmbed], withResponse: true }); } } diff --git a/src/commands/fun/shrug.ts b/src/commands/fun/shrug.ts index 10970de..ab039b8 100644 --- a/src/commands/fun/shrug.ts +++ b/src/commands/fun/shrug.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, GuildMember } from 'discord.js'; +import { EmbedBuilder, GuildMember, MessageFlagsBitField } from 'discord.js'; import { Shrug } from '#utils/gifs'; export class ShrugCommand extends Command { @@ -48,8 +48,8 @@ export class ShrugCommand extends Command { // Type checks if (!(member instanceof GuildMember)) { await interaction.reply({ - ephemeral: true, content: 'Failed to fetch your user on the bot!', + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -62,6 +62,6 @@ export class ShrugCommand extends Command { .setImage(randomShrug); // Send the embed - await interaction.reply({ embeds: [shrugEmbed], fetchReply: true }); + await interaction.reply({ embeds: [shrugEmbed], withResponse: true }); } } diff --git a/src/commands/mod/ban/ban.ts b/src/commands/mod/ban/ban.ts index 652f690..e22ecd9 100644 --- a/src/commands/mod/ban/ban.ts +++ b/src/commands/mod/ban/ban.ts @@ -18,7 +18,13 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { User, Message, Snowflake, TextChannel, Guild } from 'discord.js'; +import { + User, + Message, + Snowflake, + Guild, + MessageFlagsBitField, +} from 'discord.js'; import { EmbedBuilder } from 'discord.js'; import IDs from '#utils/ids'; import { addBan, checkBan } from '#utils/database/moderation/ban'; @@ -75,13 +81,15 @@ export class BanCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const ban = await this.ban(user.id, mod.id, reason, guild); @@ -206,21 +214,32 @@ export class BanCommand extends Command { info.success = true; // Log the ban - let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch( + const fetchLogChannel = await guild.channels.fetch( IDs.channels.logs.restricted, - )) as TextChannel | undefined; - if (logChannel === undefined) { - this.container.logger.error('Ban Error: Could not fetch log channel'); + ); + + if (fetchLogChannel === null || fetchLogChannel === undefined) { + this.container.logger.error('Ban: Could not fetch log channel'); info.message = `${user} has been banned. This hasn't been logged in a text channel as log channel could not be found`; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Ban: The bot does not have permission to send in the logs channel!', + ); + info.message = `${user} has been banned. This hasn't been logged in a text channel as the bot does not have permission to send logs!`; + + return info; + } + const log = new EmbedBuilder() .setColor('#FF0000') .setAuthor({ diff --git a/src/commands/mod/ban/tempBan.ts b/src/commands/mod/ban/tempBan.ts index 03ce4a1..c6cfc4f 100644 --- a/src/commands/mod/ban/tempBan.ts +++ b/src/commands/mod/ban/tempBan.ts @@ -19,7 +19,7 @@ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Duration, DurationFormatter } from '@sapphire/time-utilities'; -import type { User, Snowflake, TextChannel, Guild } from 'discord.js'; +import { User, Snowflake, Guild, MessageFlagsBitField } from 'discord.js'; import { EmbedBuilder, Message } from 'discord.js'; import IDs from '#utils/ids'; import { addTempBan, checkTempBan } from '#utils/database/moderation/tempBan'; @@ -79,8 +79,8 @@ export class TempBanCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -94,7 +94,9 @@ export class TempBanCommand extends Command { return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const ban = await this.ban(user.id, mod.id, time, reason, guild); @@ -273,25 +275,37 @@ export class TempBanCommand extends Command { info.success = true; // Log the ban - let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch( + const fetchLogChannel = await guild.channels.fetch( IDs.channels.logs.restricted, - )) as TextChannel | undefined; - if (logChannel === undefined) { - this.container.logger.error( - 'Temp Ban Error: Could not fetch log channel', - ); + ); + + if (fetchLogChannel === null || fetchLogChannel === undefined) { + this.container.logger.error('Temp Ban: Could not fetch log channel'); + info.message = `${user} has been temporarily banned for ${banLength}. ` + "This hasn't been logged in a text channel as log channel could not be found"; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Temp Ban: The bot does not have permission to send in the logs channel!', + ); + info.message = + `${user} has been temporarily banned for ${banLength}. ` + + "This hasn't been logged in a text channel as the bot does not have permission to send logs!"; + + return info; + } + const log = new EmbedBuilder() .setColor('#FF0000') .setAuthor({ diff --git a/src/commands/mod/ban/unban.ts b/src/commands/mod/ban/unban.ts index f6bd2cd..4bc5d7f 100644 --- a/src/commands/mod/ban/unban.ts +++ b/src/commands/mod/ban/unban.ts @@ -18,13 +18,13 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { +import { User, Message, Snowflake, - TextChannel, Guild, GuildBan, + MessageFlagsBitField, } from 'discord.js'; import { EmbedBuilder } from 'discord.js'; import IDs from '#utils/ids'; @@ -75,8 +75,8 @@ export class UnbanCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -191,21 +191,32 @@ export class UnbanCommand extends Command { info.success = true; // Log unban - let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch( + const fetchLogChannel = await guild.channels.fetch( IDs.channels.logs.restricted, - )) as TextChannel | undefined; - if (logChannel === undefined) { - this.container.logger.error('Ban Error: Could not fetch log channel'); - info.message = `${user} has been banned. This hasn't been logged in a text channel as log channel could not be found`; + ); + + if (fetchLogChannel === null || fetchLogChannel === undefined) { + this.container.logger.error('Unban Error: Could not fetch log channel'); + info.message = `${user} has been unbanned. This hasn't been logged in a text channel as log channel could not be found`; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Unban: The bot does not have permission to send in the logs channel!', + ); + info.message = `${user} has been unbanned. This hasn't been logged in a text channel as the bot does not have permission to send logs!`; + + return info; + } + const log = new EmbedBuilder() .setColor('#28A745') .setAuthor({ diff --git a/src/commands/mod/diversity.ts b/src/commands/mod/diversity.ts index bd3af96..3b7414d 100644 --- a/src/commands/mod/diversity.ts +++ b/src/commands/mod/diversity.ts @@ -25,6 +25,7 @@ import { ChannelType, GuildMember, Message, + MessageFlagsBitField, PermissionsBitField, } from 'discord.js'; import type { TextChannel, Snowflake } from 'discord.js'; @@ -93,8 +94,8 @@ export class DiversityCommand extends Subcommand { if (interaction.guild === null) { await interaction.reply({ content: 'Guild not found!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -105,8 +106,8 @@ export class DiversityCommand extends Subcommand { if (channel === undefined) { await interaction.reply({ content: 'Channel not found!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -115,8 +116,8 @@ export class DiversityCommand extends Subcommand { if (channel.type !== ChannelType.GuildText) { await interaction.reply({ content: 'Channel is not a text channel!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -128,8 +129,8 @@ export class DiversityCommand extends Subcommand { if (channel.parentId !== IDs.categories.diversity) { await interaction.reply({ content: 'Command was not run in the Diversity section!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -146,7 +147,7 @@ export class DiversityCommand extends Subcommand { await interaction.reply({ content: `${!open ? 'Opened' : 'Closed'} this channel.`, - fetchReply: true, + withResponse: true, }); } @@ -163,8 +164,8 @@ export class DiversityCommand extends Subcommand { if (user === null || guild === null || mod === null) { await interaction.reply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -177,8 +178,8 @@ export class DiversityCommand extends Subcommand { if (guildMember === undefined || diversity === undefined) { await interaction.reply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -190,7 +191,7 @@ export class DiversityCommand extends Subcommand { await this.threadManager(guildMember.id, false); await interaction.reply({ content: `Removed the ${diversity.name} role from ${user}`, - fetchReply: true, + withResponse: true, }); return; } @@ -199,7 +200,7 @@ export class DiversityCommand extends Subcommand { await this.threadManager(guildMember.id, true); await interaction.reply({ content: `Gave ${user} the ${diversity.name} role!`, - fetchReply: true, + withResponse: true, }); await user .send(`You have been given the ${diversity.name} role by ${mod}!`) diff --git a/src/commands/mod/moveall.ts b/src/commands/mod/moveall.ts index 1ca52ec..95992b9 100644 --- a/src/commands/mod/moveall.ts +++ b/src/commands/mod/moveall.ts @@ -21,7 +21,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Message } from 'discord.js'; +import { Message, MessageFlagsBitField } from 'discord.js'; import { ChannelType } from 'discord.js'; export class MoveAllCommand extends Command { @@ -61,7 +61,9 @@ export class MoveAllCommand extends Command { const { member } = interaction; const { guild } = interaction; - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); if ( channel.type !== ChannelType.GuildVoice && diff --git a/src/commands/mod/rename.ts b/src/commands/mod/rename.ts index ae32091..39832a5 100644 --- a/src/commands/mod/rename.ts +++ b/src/commands/mod/rename.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { GuildMember, Message } from 'discord.js'; +import { GuildMember, Message, MessageFlagsBitField } from 'discord.js'; export class RenameUserCommand extends Command { public constructor(context: Command.LoaderContext, options: Command.Options) { @@ -68,8 +68,8 @@ export class RenameUserCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -81,8 +81,8 @@ export class RenameUserCommand extends Command { if (member === undefined) { await interaction.reply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -93,15 +93,15 @@ export class RenameUserCommand extends Command { } catch { await interaction.reply({ content: "Bot doesn't have permission to change the user's name!", - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } await interaction.reply({ content: `Changed ${user}'s nickname`, - fetchReply: true, - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); } diff --git a/src/commands/mod/restriction/restrict.ts b/src/commands/mod/restriction/restrict.ts index c11a136..2cfb8c3 100644 --- a/src/commands/mod/restriction/restrict.ts +++ b/src/commands/mod/restriction/restrict.ts @@ -26,6 +26,7 @@ import { import { ChannelType, EmbedBuilder, + MessageFlagsBitField, PermissionsBitField, time, } from 'discord.js'; @@ -55,7 +56,7 @@ export async function restrictRun( let user = guild.client.users.cache.get(userId); if (user === undefined) { - user = await guild.client.users.fetch(userId); + user = await guild.client.users.fetch(userId).catch(() => undefined); if (user === undefined) { info.message = 'Error fetching user'; return info; @@ -242,21 +243,31 @@ export async function restrictRun( await user.send({ embeds: [dmEmbed] }).catch(() => {}); // Log the ban - let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch(IDs.channels.logs.restricted)) as - | TextChannel - | undefined; - if (logChannel === undefined) { - container.logger.error('Restrict Error: Could not fetch log channel'); + const fetchLogChannel = await guild.channels.fetch( + IDs.channels.logs.restricted, + ); + if (fetchLogChannel === null || fetchLogChannel === undefined) { + container.logger.error('Restrict: Could not fetch log channel'); info.message = `Restricted ${user} but could not find the log channel. This has been logged to the database.`; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + container.logger.error( + 'Restrict: The bot does not have permission to send in the logs channel!', + ); + info.message = `${user} has been restricted. This hasn't been logged in a text channel as the bot does not have permission to send logs!`; + + return info; + } + const message = new EmbedBuilder() .setColor('#FF6700') .setAuthor({ @@ -324,15 +335,17 @@ export class RestrictCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); - const info = await restrictRun(user?.id, mod.id, reason, guild); + const info = await restrictRun(user.id, mod.id, reason, guild); await interaction.editReply({ content: info.message, @@ -367,7 +380,7 @@ export class RestrictCommand extends Command { return; } - const info = await restrictRun(user?.id, mod.id, reason, guild); + const info = await restrictRun(user.id, mod.id, reason, guild); await message.reply(info.message); await message.react(info.success ? '✅' : '❌'); diff --git a/src/commands/mod/restriction/restrictLogs.ts b/src/commands/mod/restriction/restrictLogs.ts index 7241f78..467387a 100644 --- a/src/commands/mod/restriction/restrictLogs.ts +++ b/src/commands/mod/restriction/restrictLogs.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import { ChannelType, EmbedBuilder } from 'discord.js'; +import { ChannelType, EmbedBuilder, MessageFlagsBitField } from 'discord.js'; import type { Message, TextChannel, Guild, Snowflake } from 'discord.js'; import IDs from '#utils/ids'; import { getRestrictions } from '#utils/database/moderation/restriction'; @@ -63,8 +63,8 @@ export class RestrictLogsCommand extends Command { if (guild === null || channel === null) { await interaction.reply({ content: 'Error fetching guild or channel!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -86,7 +86,6 @@ export class RestrictLogsCommand extends Command { // Checks if the channel topic has the user's snowflake if (channel.topic !== null) { topic = channel.topic.split(' '); - // eslint-disable-next-line prefer-destructuring userId = topic[2]; } } @@ -95,8 +94,8 @@ export class RestrictLogsCommand extends Command { if (userId === null) { await interaction.reply({ content: 'User could not be found or was not provided!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -106,8 +105,8 @@ export class RestrictLogsCommand extends Command { await interaction.reply({ embeds: info.embeds, content: info.message, - fetchReply: true, - ephemeral: !staffChannel, + withResponse: true, + flags: staffChannel ? undefined : MessageFlagsBitField.Flags.Ephemeral, }); } } @@ -176,7 +175,7 @@ export class RestrictLogsCommand extends Command { let user = guild.client.users.cache.get(userId); if (user === undefined) { - user = await guild.client.users.fetch(userId); + user = await guild.client.users.fetch(userId).catch(() => undefined); if (user === undefined) { info.message = 'Error fetching user'; return info; diff --git a/src/commands/mod/restriction/restrictTolerance.ts b/src/commands/mod/restriction/restrictTolerance.ts index d36806a..a2ddc70 100644 --- a/src/commands/mod/restriction/restrictTolerance.ts +++ b/src/commands/mod/restriction/restrictTolerance.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { User, Message } from 'discord.js'; +import { User, Message, MessageFlagsBitField } from 'discord.js'; import { restrictRun } from './restrict'; export class RestrictToleranceCommand extends Command { @@ -69,15 +69,17 @@ export class RestrictToleranceCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); - const info = await restrictRun(user?.id, mod.id, reason, guild, true); + const info = await restrictRun(user.id, mod.id, reason, guild, true); await interaction.editReply({ content: info.message, @@ -112,7 +114,7 @@ export class RestrictToleranceCommand extends Command { return; } - const info = await restrictRun(user?.id, mod.id, reason, guild, true); + const info = await restrictRun(user.id, mod.id, reason, guild, true); await message.reply(info.message); await message.react(info.success ? '✅' : '❌'); diff --git a/src/commands/mod/restriction/restrictTools.ts b/src/commands/mod/restriction/restrictTools.ts index 2b16605..d71292f 100644 --- a/src/commands/mod/restriction/restrictTools.ts +++ b/src/commands/mod/restriction/restrictTools.ts @@ -19,7 +19,7 @@ import { RegisterBehavior } from '@sapphire/framework'; import { Subcommand } from '@sapphire/plugin-subcommands'; -import type { TextChannel } from 'discord.js'; +import { MessageFlagsBitField, TextChannel } from 'discord.js'; import { CategoryChannel, ChannelType } from 'discord.js'; import IDs from '#utils/ids'; @@ -78,7 +78,9 @@ export class RestrictToolsCommand extends Subcommand { const user = interaction.options.getUser('user'); const { guild, channel } = interaction; - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); // Checks if all the variables are of the right type if (guild === null || channel === null) { @@ -142,11 +144,9 @@ export class RestrictToolsCommand extends Subcommand { return; } - const category = guild.channels.cache.get(IDs.categories.restricted) as - | CategoryChannel - | undefined; + const category = guild.channels.cache.get(IDs.categories.restricted); - if (category === undefined) { + if (!(category instanceof CategoryChannel)) { await interaction.editReply({ content: 'Could not find category!', }); @@ -156,23 +156,45 @@ export class RestrictToolsCommand extends Subcommand { const textChannels = category.children.cache.filter( (c) => c.type === ChannelType.GuildText, ); - textChannels.forEach((c) => { - const textChannel = c as TextChannel; + + for (const channel of textChannels) { + const textChannel = channel[1]; + + // Checks that the channel is a text channel + if (!(textChannel instanceof TextChannel)) { + continue; + } + + // Checks that the channel has a topic + if (textChannel.topic === null) { + continue; + } + // Checks if the channel topic has the user's snowflake - if (textChannel.topic?.includes(user?.id)) { + if (textChannel.topic.includes(user.id)) { topic = textChannel.topic.split(' '); - const vcId = topic[topic.indexOf(user?.id) + 1]; - const voiceChannel = guild.channels.cache.get(vcId); + const vcId = topic[topic.indexOf(user.id) + 1]; + let voiceChannel = guild.channels.cache.get(vcId); + + if (voiceChannel === undefined) { + const fetchVoiceChannel = await guild.channels + .fetch(vcId) + .catch(() => undefined); + + if (fetchVoiceChannel !== null && fetchVoiceChannel !== undefined) { + voiceChannel = fetchVoiceChannel; + } + } if ( voiceChannel !== undefined && voiceChannel.parentId === IDs.categories.restricted ) { - voiceChannel.delete(); + await voiceChannel.delete(); } - textChannel.delete(); + await textChannel.delete(); } - }); + } await interaction.editReply({ content: `Successfully deleted the channel for ${user}`, diff --git a/src/commands/mod/restriction/unrestrict.ts b/src/commands/mod/restriction/unrestrict.ts index d7e87a6..6f6599e 100644 --- a/src/commands/mod/restriction/unrestrict.ts +++ b/src/commands/mod/restriction/unrestrict.ts @@ -18,13 +18,19 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import { CategoryChannel, ChannelType, EmbedBuilder } from 'discord.js'; -import type { User, Message, TextChannel, Guild, Snowflake } from 'discord.js'; -import IDs from '#utils/ids'; -import { fetchRoles, addExistingUser } from '#utils/database/dbExistingUser'; +import type { Guild, Message, Snowflake, User } from 'discord.js'; +import { + CategoryChannel, + ChannelType, + EmbedBuilder, + MessageFlagsBitField, + TextChannel, +} from 'discord.js'; +import IDs from '#utils/ids'; +import { addExistingUser, fetchRoles } from '#utils/database/dbExistingUser'; import { - unRestrict, checkActive, + unRestrict, unRestrictLegacy, } from '#utils/database/moderation/restriction'; @@ -69,14 +75,14 @@ export class UnRestrictCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } await interaction.deferReply(); - const info = await this.unRestrictRun(user?.id, mod.id, guild); + const info = await this.unRestrictRun(user.id, mod.id, guild); await interaction.editReply({ content: info.message, @@ -108,7 +114,7 @@ export class UnRestrictCommand extends Command { const channelRun = message.channel; const info = await this.unRestrictRun( - user?.id, + user.id, mod.id, guild, channelRun.id, @@ -135,7 +141,8 @@ export class UnRestrictCommand extends Command { let user = guild.client.users.cache.get(userId); if (user === undefined) { - user = await guild.client.users.fetch(userId); + user = await guild.client.users.fetch(userId).catch(() => undefined); + if (user === undefined) { info.message = 'Error fetching user'; return info; @@ -159,11 +166,12 @@ export class UnRestrictCommand extends Command { if (member === undefined) { member = await guild.members.fetch(userId).catch(() => undefined); - } - if (member === undefined) { - info.message = "Can't unrestrict the user as they are not on this server"; - return info; + if (member === undefined) { + info.message = + "Can't unrestrict the user as they are not on this server"; + return info; + } } // Check if user is in database @@ -180,16 +188,20 @@ export class UnRestrictCommand extends Command { if (await checkActive(userId)) { const roles = await fetchRoles(userId); await member.roles.add(roles); + // Unrestricts the user on the database await unRestrict(userId, modId); } else { let section = 1; + for (let i = 0; i < restrictRoles.length; i += 1) { if (member.roles.cache.has(restrictRoles[i])) { section = i + 1; } } + await member.roles.add(IDs.roles.nonvegan.nonvegan); + // Unrestricts the user on the database but for restricts done on the old bot await unRestrictLegacy(userId, modId, section); } @@ -198,59 +210,94 @@ export class UnRestrictCommand extends Command { // Remove vegan restrict channels if (member.roles.cache.has(IDs.roles.vegan.vegan)) { - const category = guild.channels.cache.get(IDs.categories.restricted) as - | CategoryChannel - | undefined; + const category = guild.channels.cache.get(IDs.categories.restricted); + + if (!(category instanceof CategoryChannel)) { + info.message = + 'Could not find the restricted category! The channels will have to be deleted manually.'; + return info; + } let topic: string[]; - if (category !== undefined) { - const textChannels = category.children.cache.filter( - (c) => c.type === ChannelType.GuildText, - ); - textChannels.forEach((c) => { - const textChannel = c as TextChannel; - // Checks if the channel topic has the user's snowflake - if (textChannel.topic?.includes(userId)) { - if (textChannel.id === channelRun) { - info.runInVeganRestrict = true; - } - topic = textChannel.topic.split(' '); - const vcId = topic[topic.indexOf(userId) + 1]; - const voiceChannel = guild.channels.cache.get(vcId); + const textChannels = category.children.cache.filter( + (c) => c.type === ChannelType.GuildText, + ); - if ( - voiceChannel !== undefined && - voiceChannel.parentId === IDs.categories.restricted - ) { - voiceChannel.delete(); - } - textChannel.delete(); + for (const channel of textChannels) { + const textChannel = channel[1]; + + // Checks that the channel is a text channel + if (!(textChannel instanceof TextChannel)) { + continue; + } + + // Checks that the channel has a topic + if (textChannel.topic === null) { + continue; + } + + // Checks if the channel topic has the user's snowflake + if (textChannel.topic.includes(userId)) { + if (textChannel.id === channelRun) { + info.runInVeganRestrict = true; } - }); + + topic = textChannel.topic.split(' '); + const vcId = topic[topic.indexOf(user.id) + 1]; + let voiceChannel = guild.channels.cache.get(vcId); + + if (voiceChannel === undefined) { + const fetchVoiceChannel = await guild.channels + .fetch(vcId) + .catch(() => undefined); + + if (fetchVoiceChannel !== null && fetchVoiceChannel !== undefined) { + voiceChannel = fetchVoiceChannel; + } + } + + if ( + voiceChannel !== undefined && + // Used for sanitising the channel topic, so another voice channel does not get deleted + voiceChannel.parentId === IDs.categories.restricted + ) { + await voiceChannel.delete(); + } + + await textChannel.delete(); + } } } info.success = true; // Log the ban - let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch( + const fetchLogChannel = await guild.channels.fetch( IDs.channels.logs.restricted, - )) as TextChannel | undefined; - if (logChannel === undefined) { - this.container.logger.error( - 'Restrict Error: Could not fetch log channel', - ); + ); + if (fetchLogChannel === null || fetchLogChannel === undefined) { + this.container.logger.error('Unrestrict: Could not fetch log channel'); info.message = `Unrestricted ${user} but could not find the log channel. This has been logged to the database.`; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Unrestrict: The bot does not have permission to send in the logs channel!', + ); + info.message = `Unrestricted ${user} but could not find the log channel. This hasn't been logged in a text channel as the bot does not have permission to send logs!`; + + return info; + } + const message = new EmbedBuilder() .setColor('#28A745') .setAuthor({ diff --git a/src/commands/mod/slowmode.ts b/src/commands/mod/slowmode.ts index a80315e..bcb0d67 100644 --- a/src/commands/mod/slowmode.ts +++ b/src/commands/mod/slowmode.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Message, TextBasedChannel } from 'discord.js'; +import { Message, MessageFlagsBitField, TextBasedChannel } from 'discord.js'; import { ChannelType } from 'discord.js'; import { Duration, DurationFormatter } from '@sapphire/time-utilities'; import { isNumber } from '#utils/maths'; @@ -61,8 +61,8 @@ export class SlowmodeCommand extends Command { if (channel === null) { await interaction.reply({ content: 'Could not fetch channel!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } diff --git a/src/commands/mod/softMute.ts b/src/commands/mod/softMute.ts index 5d8e4d4..0a6dfc5 100644 --- a/src/commands/mod/softMute.ts +++ b/src/commands/mod/softMute.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { GuildMember, Message } from 'discord.js'; +import { GuildMember, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; export class SoftMuteCommand extends Command { @@ -64,8 +64,8 @@ export class SoftMuteCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching the guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -77,8 +77,8 @@ export class SoftMuteCommand extends Command { if (guildMember === undefined) { await interaction.reply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -87,7 +87,7 @@ export class SoftMuteCommand extends Command { await guildMember.roles.remove(IDs.roles.restrictions.softMute); await interaction.reply({ content: `Removed soft muted for ${user}`, - fetchReply: true, + withResponse: true, }); return; } @@ -96,7 +96,7 @@ export class SoftMuteCommand extends Command { await interaction.reply({ content: `Soft muted ${user}`, - fetchReply: true, + withResponse: true, }); } diff --git a/src/commands/mod/vcMute.ts b/src/commands/mod/vcMute.ts index a4e2fbc..763f367 100644 --- a/src/commands/mod/vcMute.ts +++ b/src/commands/mod/vcMute.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { GuildMember, Message } from 'discord.js'; +import { GuildMember, Message, MessageFlagsBitField } from 'discord.js'; import { addMute, removeMute, @@ -73,8 +73,8 @@ export class VCMuteCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -87,8 +87,8 @@ export class VCMuteCommand extends Command { if (member === undefined || mod === undefined) { await interaction.reply({ content: 'Error fetching user!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -102,8 +102,8 @@ export class VCMuteCommand extends Command { await interaction.reply({ content: `Removed server mute from ${user}`, - fetchReply: true, - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -118,8 +118,8 @@ export class VCMuteCommand extends Command { await addMute(member.id, mod.id, reason); await interaction.reply({ content: `Server muted ${user}`, - fetchReply: true, - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); } diff --git a/src/commands/mod/warning/deleteWarning.ts b/src/commands/mod/warning/deleteWarning.ts index ad3638b..c443aad 100644 --- a/src/commands/mod/warning/deleteWarning.ts +++ b/src/commands/mod/warning/deleteWarning.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import { EmbedBuilder, TextChannel } from 'discord.js'; +import { EmbedBuilder, MessageFlagsBitField } from 'discord.js'; import type { Message, Guild, User } from 'discord.js'; import IDs from '#utils/ids'; import { @@ -68,15 +68,17 @@ export class DeleteWarningCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } const staffChannel = checkStaff(interaction.channel); - await interaction.deferReply({ ephemeral: !staffChannel }); + await interaction.deferReply({ + flags: staffChannel ? undefined : MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.deleteWarning(warningId, mod, guild); @@ -145,25 +147,37 @@ export class DeleteWarningCommand extends Command { } // Log the warnings deletion - let logChannel = guild.channels.cache.get(IDs.channels.logs.sus) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.sus); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch(IDs.channels.logs.sus)) as - | TextChannel - | undefined; - if (logChannel === undefined) { + const fetchLogChannel = await guild.channels + .fetch(IDs.channels.logs.sus) + .catch(() => undefined); + if (fetchLogChannel === null || fetchLogChannel === undefined) { this.container.logger.error( - 'Delete Warning Error: Could not fetch log channel', + 'Delete Warning: Could not fetch log channel', ); info.message = `Deleted warning for ${user} (Warning ID: ${warningId} but ` + 'could not find the log channel.'; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Delete Warning: The bot does not have permission to send in the logs channel!', + ); + info.message = + `Deleted warning for ${user} (Warning ID: ${warningId} but ` + + "But this hasn't been logged in a text channel as the bot does not have permission to send logs!"; + + return info; + } + const message = new EmbedBuilder() .setColor('#28A745') .setAuthor({ diff --git a/src/commands/mod/warning/warn.ts b/src/commands/mod/warning/warn.ts index a022318..b91be8f 100644 --- a/src/commands/mod/warning/warn.ts +++ b/src/commands/mod/warning/warn.ts @@ -17,16 +17,17 @@ along with this program. If not, see . */ +import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { - Args, - Command, - container, - RegisterBehavior, -} from '@sapphire/framework'; -import type { User, Message, Snowflake, Guild, TextChannel } from 'discord.js'; + EmbedBuilder, + Guild, + Message, + MessageFlagsBitField, + Snowflake, + User, +} from 'discord.js'; import { updateUser } from '#utils/database/dbExistingUser'; import { addWarn } from '#utils/database/moderation/warnings'; -import { EmbedBuilder } from 'discord.js'; import IDs from '#utils/ids'; export class WarnCommand extends Command { @@ -76,8 +77,8 @@ export class WarnCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -190,21 +191,32 @@ export class WarnCommand extends Command { await user.send({ embeds: [dmEmbed] }).catch(() => {}); // Log the ban - let logChannel = guild.channels.cache.get(IDs.channels.logs.sus) as - | TextChannel - | undefined; + let logChannel = guild.channels.cache.get(IDs.channels.logs.sus); if (logChannel === undefined) { - logChannel = (await guild.channels.fetch(IDs.channels.logs.sus)) as - | TextChannel - | undefined; - if (logChannel === undefined) { - container.logger.error('Warn Error: Could not fetch log channel'); + const fetchLogChannel = await guild.channels + .fetch(IDs.channels.logs.sus) + .catch(() => undefined); + + if (fetchLogChannel === null || fetchLogChannel === undefined) { + this.container.logger.error('Warn: Could not fetch log channel'); info.message = `Warned ${user} but could not find the log channel. This has been logged to the database.`; + return info; + } else { + logChannel = fetchLogChannel; } } + if (!logChannel.isSendable()) { + this.container.logger.error( + 'Warn: The bot does not have permission to send in the logs channel!', + ); + info.message = `Warned ${user}, but the bot does not have permission to send in the logs channel!`; + + return info; + } + const message = new EmbedBuilder() .setColor('#FF6700') .setAuthor({ diff --git a/src/commands/mod/warning/warnings.ts b/src/commands/mod/warning/warnings.ts index 20f5b85..ea68dcc 100644 --- a/src/commands/mod/warning/warnings.ts +++ b/src/commands/mod/warning/warnings.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import { ChannelType, EmbedBuilder } from 'discord.js'; +import { ChannelType, EmbedBuilder, MessageFlagsBitField } from 'discord.js'; import type { Message, Guild, User } from 'discord.js'; import IDs from '#utils/ids'; import { fetchWarnings } from '#utils/database/moderation/warnings'; @@ -65,15 +65,17 @@ export class WarningsCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } const staffChannel = checkStaff(interaction.channel); - await interaction.deferReply({ ephemeral: !staffChannel }); + await interaction.deferReply({ + flags: staffChannel ? undefined : MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.warnings(user, guild); diff --git a/src/commands/outreach/outreach.ts b/src/commands/outreach/outreach.ts index 7829006..43d2b0f 100644 --- a/src/commands/outreach/outreach.ts +++ b/src/commands/outreach/outreach.ts @@ -19,7 +19,12 @@ import { Subcommand } from '@sapphire/plugin-subcommands'; import { RegisterBehavior } from '@sapphire/framework'; -import { ChannelType, PermissionsBitField, Snowflake } from 'discord.js'; +import { + ChannelType, + MessageFlagsBitField, + PermissionsBitField, + Snowflake, +} from 'discord.js'; import { updateUser } from '#utils/database/dbExistingUser'; import { addStatUser, @@ -190,7 +195,7 @@ export class OutreachCommand extends Subcommand { if (guild === null) { await interaction.reply({ content: 'Mod or guild was not found!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -200,7 +205,7 @@ export class OutreachCommand extends Subcommand { if (mod === undefined) { await interaction.reply({ content: 'Outreach Leader was not found!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -208,7 +213,7 @@ export class OutreachCommand extends Subcommand { if (!mod.roles.cache.has(IDs.roles.staff.outreachLeader)) { await interaction.reply({ content: 'You need to be an Outreach Leader to run this command!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -216,7 +221,7 @@ export class OutreachCommand extends Subcommand { if (await checkActiveEvent()) { await interaction.reply({ content: 'There is already an active event!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -227,7 +232,7 @@ export class OutreachCommand extends Subcommand { await interaction.reply({ content: 'Created the event!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); } @@ -238,7 +243,7 @@ export class OutreachCommand extends Subcommand { if (guild === null) { await interaction.reply({ content: 'Guild not found!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -248,7 +253,7 @@ export class OutreachCommand extends Subcommand { if (mod === undefined) { await interaction.reply({ content: 'Your guild member was not found!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } @@ -256,12 +261,14 @@ export class OutreachCommand extends Subcommand { if (!mod.roles.cache.has(IDs.roles.staff.outreachLeader)) { await interaction.reply({ content: 'You need to be an Outreach Leader to run this command!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const event = await getCurrentEvent(); @@ -351,12 +358,14 @@ export class OutreachCommand extends Subcommand { if (guild === null) { await interaction.reply({ content: 'Guild not found!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); if ((await getStatFromLeader(leader.id)) !== null) { await interaction.editReply( @@ -462,12 +471,14 @@ export class OutreachCommand extends Subcommand { if (guild === null) { await interaction.reply({ content: 'Could not find guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); let statId: number; let roleId: Snowflake | undefined; @@ -571,12 +582,14 @@ export class OutreachCommand extends Subcommand { if (leader === null) { await interaction.reply({ content: 'Could not find your user!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const stat = await getStatFromLeader(leader.id); diff --git a/src/commands/roles/bookClub.ts b/src/commands/roles/bookClub.ts index ba5ae83..398aadc 100644 --- a/src/commands/roles/bookClub.ts +++ b/src/commands/roles/bookClub.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class BookClubCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageBookClub(user, mod, guild); diff --git a/src/commands/roles/debateHost.ts b/src/commands/roles/debateHost.ts index aba29a5..2f409be 100644 --- a/src/commands/roles/debateHost.ts +++ b/src/commands/roles/debateHost.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class DebateHostCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageDebateHost(user, mod, guild); diff --git a/src/commands/roles/gameNightHost.ts b/src/commands/roles/gameNightHost.ts index 96f6b89..f8a8645 100644 --- a/src/commands/roles/gameNightHost.ts +++ b/src/commands/roles/gameNightHost.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class GameNightHostCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageGameNight(user, mod, guild); diff --git a/src/commands/roles/guest.ts b/src/commands/roles/guest.ts index 112c2be..6cf7f90 100644 --- a/src/commands/roles/guest.ts +++ b/src/commands/roles/guest.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class GuestCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageGuest(user, mod, guild); diff --git a/src/commands/roles/staff/mentor.ts b/src/commands/roles/staff/mentor.ts index 84a81e9..8969374 100644 --- a/src/commands/roles/staff/mentor.ts +++ b/src/commands/roles/staff/mentor.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class MentorCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageMentor(user, mod, guild); diff --git a/src/commands/roles/staff/mod.ts b/src/commands/roles/staff/mod.ts index 132ea8e..4074dd0 100644 --- a/src/commands/roles/staff/mod.ts +++ b/src/commands/roles/staff/mod.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class ModCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageMod(user, mod, guild); diff --git a/src/commands/roles/staff/restrictedAccess.ts b/src/commands/roles/staff/restrictedAccess.ts index d7eef8a..7991beb 100644 --- a/src/commands/roles/staff/restrictedAccess.ts +++ b/src/commands/roles/staff/restrictedAccess.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class RestrictedAccessCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageRestrictedAccess(user, mod, guild); diff --git a/src/commands/roles/staff/stagehost.ts b/src/commands/roles/staff/stagehost.ts index 565eba4..d7df6bf 100644 --- a/src/commands/roles/staff/stagehost.ts +++ b/src/commands/roles/staff/stagehost.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class StageHostCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageStageHost(user, mod, guild); diff --git a/src/commands/roles/staff/trialMod.ts b/src/commands/roles/staff/trialMod.ts index d17855f..38c6652 100644 --- a/src/commands/roles/staff/trialMod.ts +++ b/src/commands/roles/staff/trialMod.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class TrialModCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageMod(user, mod, guild); diff --git a/src/commands/roles/staff/trialVerifier.ts b/src/commands/roles/staff/trialVerifier.ts index 8965ce9..ee767f3 100644 --- a/src/commands/roles/staff/trialVerifier.ts +++ b/src/commands/roles/staff/trialVerifier.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class TrialVerifierCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageTrialVerifier(user, mod, guild); diff --git a/src/commands/roles/staff/verifier.ts b/src/commands/roles/staff/verifier.ts index b3e87c9..3b1d620 100644 --- a/src/commands/roles/staff/verifier.ts +++ b/src/commands/roles/staff/verifier.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -62,13 +62,15 @@ export class VerifierCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageVerifier(user, mod, guild); diff --git a/src/commands/roles/verification/activist.ts b/src/commands/roles/verification/activist.ts index 09264df..b69f5b9 100644 --- a/src/commands/roles/verification/activist.ts +++ b/src/commands/roles/verification/activist.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -65,13 +65,15 @@ export class ActivistCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageActivist(user, mod, guild); diff --git a/src/commands/roles/verification/aravegan.ts b/src/commands/roles/verification/aravegan.ts index 78c17d3..199b750 100644 --- a/src/commands/roles/verification/aravegan.ts +++ b/src/commands/roles/verification/aravegan.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -64,13 +64,15 @@ export class ARAVeganCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageVegan(user, mod, guild); diff --git a/src/commands/roles/verification/convinced.ts b/src/commands/roles/verification/convinced.ts index dc1acd0..45a5011 100644 --- a/src/commands/roles/verification/convinced.ts +++ b/src/commands/roles/verification/convinced.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class ConvincedCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageConvinced(user, mod, guild); diff --git a/src/commands/roles/verification/plus.ts b/src/commands/roles/verification/plus.ts index 3cc8ba4..4f355d1 100644 --- a/src/commands/roles/verification/plus.ts +++ b/src/commands/roles/verification/plus.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,7 +63,7 @@ export class PlusCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } diff --git a/src/commands/roles/verification/trusted.ts b/src/commands/roles/verification/trusted.ts index b6ac006..fd27d7b 100644 --- a/src/commands/roles/verification/trusted.ts +++ b/src/commands/roles/verification/trusted.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class TrustedCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageTrusted(user, mod, guild); diff --git a/src/commands/roles/verification/vegan.ts b/src/commands/roles/verification/vegan.ts index edaa0e4..0888cfb 100644 --- a/src/commands/roles/verification/vegan.ts +++ b/src/commands/roles/verification/vegan.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -65,13 +65,15 @@ export class VeganCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageVegan(user, mod, guild); diff --git a/src/commands/roles/verification/vegcurious.ts b/src/commands/roles/verification/vegcurious.ts index 0cf6d28..43e13df 100644 --- a/src/commands/roles/verification/vegcurious.ts +++ b/src/commands/roles/verification/vegcurious.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Guild, User, Message } from 'discord.js'; +import { Guild, User, Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; import { roleAddLog, roleRemoveLog } from '#utils/logging/role'; @@ -63,13 +63,15 @@ export class VegCuriousCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); const info = await this.manageVegCurious(user, mod, guild); diff --git a/src/commands/utils/apply.ts b/src/commands/utils/apply.ts index 072690e..d6ddf7a 100644 --- a/src/commands/utils/apply.ts +++ b/src/commands/utils/apply.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import type { Message } from 'discord.js'; +import { Message, MessageFlagsBitField } from 'discord.js'; export class ApplyCommand extends Command { public constructor(context: Command.LoaderContext, options: Command.Options) { @@ -47,8 +47,8 @@ export class ApplyCommand extends Command { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { await interaction.reply({ content: this.message, - fetchReply: true, - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); } diff --git a/src/commands/utils/count.ts b/src/commands/utils/count.ts index 427fa1f..f2757a2 100644 --- a/src/commands/utils/count.ts +++ b/src/commands/utils/count.ts @@ -18,7 +18,7 @@ */ import { Command, RegisterBehavior } from '@sapphire/framework'; -import type { Message } from 'discord.js'; +import { Message, MessageFlagsBitField } from 'discord.js'; import IDs from '#utils/ids'; export class RenameUserCommand extends Command { @@ -47,22 +47,22 @@ export class RenameUserCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } await guild.members.fetch(); - const vegan = await guild.roles.cache.get(IDs.roles.vegan.vegan); - const notVegan = await guild.roles.cache.get(IDs.roles.nonvegan.nonvegan); + const vegan = guild.roles.cache.get(IDs.roles.vegan.vegan); + const notVegan = guild.roles.cache.get(IDs.roles.nonvegan.nonvegan); if (vegan === undefined || notVegan === undefined) { await interaction.reply({ content: 'Error fetching roles!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -71,7 +71,7 @@ export class RenameUserCommand extends Command { content: `${vegan.name}s: \`${vegan.members.size}\`` + `\n${notVegan.name}s: \`${notVegan.members.size}\``, - fetchReply: true, + withResponse: true, }); } @@ -88,8 +88,8 @@ export class RenameUserCommand extends Command { await guild.members.fetch(); - const vegan = await guild.roles.cache.get(IDs.roles.vegan.vegan); - const notVegan = await guild.roles.cache.get(IDs.roles.nonvegan.nonvegan); + const vegan = guild.roles.cache.get(IDs.roles.vegan.vegan); + const notVegan = guild.roles.cache.get(IDs.roles.nonvegan.nonvegan); if (vegan === undefined || notVegan === undefined) { await message.react('❌'); diff --git a/src/commands/utils/info.ts b/src/commands/utils/info.ts index c4e9660..5a08cc3 100644 --- a/src/commands/utils/info.ts +++ b/src/commands/utils/info.ts @@ -19,6 +19,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import IDs from '#utils/ids'; +import { MessageFlagsBitField } from 'discord.js'; export class InfoCommand extends Command { public constructor(context: Command.LoaderContext, options: Command.Options) { @@ -66,11 +67,7 @@ export class InfoCommand extends Command { const option = interaction.options.getString('info', true); let ephemeral = interaction.options.getBoolean('visible'); - if (ephemeral === null) { - ephemeral = true; - } else { - ephemeral = !ephemeral; - } + ephemeral = ephemeral !== true; let message: string; @@ -115,7 +112,7 @@ export class InfoCommand extends Command { await interaction.reply({ content: message, - ephemeral, + flags: ephemeral ? MessageFlagsBitField.Flags.Ephemeral : undefined, }); } } diff --git a/src/commands/verification/verify.ts b/src/commands/verification/verify.ts index efd3b6d..d16798d 100644 --- a/src/commands/verification/verify.ts +++ b/src/commands/verification/verify.ts @@ -18,7 +18,13 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { Message, User, Guild, Snowflake } from 'discord.js'; +import { + Message, + User, + Guild, + Snowflake, + MessageFlagsBitField, +} from 'discord.js'; import IDs from '#utils/ids'; import { finishVerifyMessages, @@ -77,8 +83,8 @@ export class VerifyCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } @@ -93,7 +99,7 @@ export class VerifyCommand extends Command { await interaction.reply({ content: verify.message, - fetchReply: true, + withResponse: true, }); } diff --git a/src/commands/verification/verifyTimeoutRemove.ts b/src/commands/verification/verifyTimeoutRemove.ts index c0e9df7..1dab908 100644 --- a/src/commands/verification/verifyTimeoutRemove.ts +++ b/src/commands/verification/verifyTimeoutRemove.ts @@ -20,6 +20,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import IDs from '#utils/ids'; import { checkVerificationFinish } from '#utils/database/verification'; +import { MessageFlagsBitField } from 'discord.js'; export class VerifyTimeoutRemoveCommand extends Command { public constructor(context: Command.LoaderContext, options: Command.Options) { @@ -60,13 +61,15 @@ export class VerifyTimeoutRemoveCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Error fetching guild!', - ephemeral: true, - fetchReply: true, + flags: MessageFlagsBitField.Flags.Ephemeral, + withResponse: true, }); return; } - await interaction.deferReply({ ephemeral: true }); + await interaction.deferReply({ + flags: MessageFlagsBitField.Flags.Ephemeral, + }); let member = guild.members.cache.get(user.id); diff --git a/src/commands/xp/rank.ts b/src/commands/xp/rank.ts index f8fa740..7952f5b 100644 --- a/src/commands/xp/rank.ts +++ b/src/commands/xp/rank.ts @@ -18,7 +18,7 @@ */ import { Args, Command, RegisterBehavior } from '@sapphire/framework'; -import type { User, Guild, Message } from 'discord.js'; +import { User, Guild, Message, MessageFlagsBitField } from 'discord.js'; import { EmbedBuilder } from 'discord.js'; import { getRank, xpToNextLevel } from '#utils/database/fun/xp'; @@ -55,7 +55,7 @@ export class RankCommand extends Command { if (guild === null) { await interaction.reply({ content: 'Could not find the guild!', - ephemeral: true, + flags: MessageFlagsBitField.Flags.Ephemeral, }); return; } diff --git a/src/listeners/fixRoles.ts b/src/listeners/fixRoles.ts index 5a87762..dcbb69e 100644 --- a/src/listeners/fixRoles.ts +++ b/src/listeners/fixRoles.ts @@ -134,11 +134,7 @@ export class FixRolesOnReady extends Listener { if ( restricted || - member.roles.cache.has(IDs.roles.restrictions.restricted1) || - member.roles.cache.has(IDs.roles.restrictions.restricted2) || - member.roles.cache.has(IDs.roles.restrictions.restricted3) || - member.roles.cache.has(IDs.roles.restrictions.restricted4) || - member.roles.cache.has(IDs.roles.restrictions.restrictedVegan) + member.roles.cache.hasAny(...IDs.roles.restrictions.restricted) ) { continue; }