styling fixes and some typing
diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts
index 87bfd28..4f2d4d7 100644
--- a/src/commands/mod/ban.ts
+++ b/src/commands/mod/ban.ts
@@ -1,5 +1,5 @@
import { CommandInteraction, GuildMember, MessageActionRow, MessageButton } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
@@ -160,24 +160,24 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow banning the owner
- if (member.id === interaction.guild.ownerId) throw "You cannot ban the owner of the server";
+ if (member.id === interaction.guild.ownerId) throw new Error("You cannot ban the owner of the server");
// Check if Nucleus can ban the member
- if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to ban
- if (!me.permissions.has("BAN_MEMBERS")) throw "I do not have the *Ban Members* permission";
+ if (!me.permissions.has("BAN_MEMBERS")) throw new Error("I do not have the *Ban Members* permission");
// Do not allow banning Nucleus
- if (member.id === interaction.guild.me.id) throw "I cannot ban myself";
+ if (member.id === interaction.guild.me.id) throw new Error("I cannot ban myself");
// Allow the owner to ban anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has ban_members permission
- if (!member.permissions.has("BAN_MEMBERS")) throw "You do not have the *Ban Members* permission";
+ if (!member.permissions.has("BAN_MEMBERS")) throw new Error("You do not have the *Ban Members* permission");
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow ban
return true;
};
diff --git a/src/commands/mod/info.ts b/src/commands/mod/info.ts
index af30989..f0257f8 100644
--- a/src/commands/mod/info.ts
+++ b/src/commands/mod/info.ts
@@ -1,12 +1,16 @@
-import { HistorySchema } from "../../utils/database.js";
+import type { HistorySchema } from "../../utils/database.js";
import Discord, {
CommandInteraction,
GuildMember,
+ Interaction,
+ Message,
MessageActionRow,
MessageButton,
+ MessageComponentInteraction,
+ ModalSubmitInteraction,
TextInputComponent
} from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
import client from "../../utils/client.js";
@@ -21,7 +25,7 @@
option.setName("user").setDescription("The user to get information about").setRequired(true)
);
-const types = {
+const types: Record<string, { emoji: string; text: string }> = {
warn: { emoji: "PUNISH.WARN.YELLOW", text: "Warned" },
mute: { emoji: "PUNISH.MUTE.YELLOW", text: "Muted" },
unmute: { emoji: "PUNISH.MUTE.GREEN", text: "Unmuted" },
@@ -36,8 +40,9 @@
};
function historyToString(history: HistorySchema) {
- let s = `${getEmojiByName(types[history.type].emoji)} ${history.amount ? history.amount + " " : ""}${
- types[history.type].text
+ if (!Object.keys(types).includes(history.type)) throw new Error("Invalid history type");
+ let s = `${getEmojiByName(types[history.type]!.emoji)} ${history.amount ? history.amount + " " : ""}${
+ types[history.type]!.text
} on <t:${Math.round(history.occurredAt.getTime() / 1000)}:F>`;
if (history.moderator) {
s += ` by <@${history.moderator}>`;
@@ -55,7 +60,7 @@
}
class TimelineSection {
- name: string;
+ name: string = "";
content: { data: HistorySchema; rendered: string }[] = [];
addContent = (content: { data: HistorySchema; rendered: string }) => {
@@ -66,8 +71,8 @@
return this.content.reduce((acc, cur) => acc + cur.rendered.length, 0);
};
generateName = () => {
- const first = Math.round(this.content[0].data.occurredAt.getTime() / 1000);
- const last = Math.round(this.content[this.content.length - 1].data.occurredAt.getTime() / 1000);
+ const first = Math.round(this.content[0]!.data.occurredAt.getTime() / 1000);
+ const last = Math.round(this.content[this.content.length - 1]!.data.occurredAt.getTime() / 1000);
if (first === last) {
return (this.name = `<t:${first}:F>`);
}
@@ -90,30 +95,36 @@
"December"
];
-async function showHistory(member, interaction: CommandInteraction) {
+async function showHistory(member: Discord.GuildMember, interaction: CommandInteraction) {
let currentYear = new Date().getFullYear();
- let pageIndex = null;
- let m, history, current;
+ let pageIndex: number | null = null;
+ let history, current: TimelineSection;
+ let m: Message;
let refresh = true;
- let filteredTypes = [];
+ let filteredTypes: string[] = [];
let openFilterPane = false;
while (true) {
if (refresh) {
history = await client.database.history.read(member.guild.id, member.id, currentYear);
- history = history.sort((a, b) => b.occurredAt.getTime() - a.occurredAt.getTime()).reverse();
+ history = history
+ .sort(
+ (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
+ b.occurredAt.getTime() - a.occurredAt.getTime()
+ )
+ .reverse();
if (openFilterPane) {
let tempFilteredTypes = filteredTypes;
if (filteredTypes.length === 0) {
tempFilteredTypes = Object.keys(types);
}
- history = history.filter((h) => tempFilteredTypes.includes(h.type));
+ history = history.filter((h: { type: string }) => tempFilteredTypes.includes(h.type));
}
refresh = false;
}
const groups: TimelineSection[] = [];
if (history.length > 0) {
current = new TimelineSection();
- history.forEach((event) => {
+ history.forEach((event: HistorySchema) => {
if (current.contentLength() + historyToString(event).length > 2000 || current.content.length === 5) {
groups.push(current);
current.generateName();
@@ -130,6 +141,7 @@
pageIndex = groups.length - 1;
}
}
+ if (pageIndex === null) pageIndex = 0;
const components = (
openFilterPane
? [
@@ -192,8 +204,8 @@
" " +
currentYear.toString();
if (groups.length > 0) {
- const toRender = groups[Math.min(pageIndex, groups.length - 1)];
- m = await interaction.editReply({
+ const toRender = groups[Math.min(pageIndex, groups.length - 1)]!;
+ m = (await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")
@@ -207,9 +219,9 @@
})
],
components: components
- });
+ })) as Message;
} else {
- m = await interaction.editReply({
+ m = (await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")
@@ -221,9 +233,9 @@
})
],
components: components
- });
+ })) as Message;
}
- let i;
+ let i: MessageComponentInteraction;
try {
i = await m.awaitMessageComponent({ time: 300000 });
} catch (e) {
@@ -232,7 +244,7 @@
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")
.setTitle("Moderation history for " + member.user.username)
- .setDescription(m.embeds[0].description)
+ .setDescription(m.embeds[0]!.description!)
.setStatus("Danger")
.setFooter({ text: "Message timed out" })
]
@@ -256,16 +268,16 @@
refresh = true;
}
if (i.customId === "prevPage") {
- pageIndex--;
- if (pageIndex < 0) {
+ pageIndex!--;
+ if (pageIndex! < 0) {
pageIndex = null;
currentYear--;
refresh = true;
}
}
if (i.customId === "nextPage") {
- pageIndex++;
- if (pageIndex >= groups.length) {
+ pageIndex!++;
+ if (pageIndex! >= groups.length) {
pageIndex = 0;
currentYear++;
refresh = true;
@@ -286,8 +298,8 @@
}
}
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
- let m;
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
+ let m: Message;
const member = interaction.options.getMember("user") as Discord.GuildMember;
await interaction.reply({
embeds: [new EmojiEmbed().setEmoji("NUCLEUS.LOADING").setTitle("Downloading Data").setStatus("Danger")],
@@ -302,7 +314,7 @@
await showHistory(member, interaction);
}
firstLoad = false;
- m = await interaction.editReply({
+ m = (await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")
@@ -324,8 +336,8 @@
.setEmoji(getEmojiByName("ICONS.HISTORY", "id"))
])
]
- });
- let i;
+ })) as Message;
+ let i: MessageComponentInteraction;
try {
i = await m.awaitMessageComponent({ time: 300000 });
} catch (e) {
@@ -370,13 +382,16 @@
try {
out = await modalInteractionCollector(
m,
- (m) => m.channel.id === interaction.channel.id,
+ (m: Interaction) =>
+ (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === interaction.channelId,
(m) => m.customId === "modify"
);
} catch (e) {
- continue;
+ break;
}
- if (out.fields) {
+ if (out === null) {
+ continue;
+ } else if (out instanceof ModalSubmitInteraction) {
const toAdd = out.fields.getTextInputValue("note") || null;
await client.database.notes.create(member.guild.id, member.id, toAdd);
} else {
@@ -391,7 +406,8 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
- if (!member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the *Moderate Members* permission";
+ if (!member.permissions.has("MODERATE_MEMBERS"))
+ throw new Error("You do not have the *Moderate Members* permission");
return true;
};
diff --git a/src/commands/mod/kick.ts b/src/commands/mod/kick.ts
index f10563e..d5b5b7a 100644
--- a/src/commands/mod/kick.ts
+++ b/src/commands/mod/kick.ts
@@ -12,7 +12,7 @@
.setDescription("Kicks a user from the server")
.addUserOption((option) => option.setName("user").setDescription("The user to kick").setRequired(true));
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { renderUser } = client.logger;
// TODO:[Modals] Replace this with a modal
let reason = null;
@@ -154,24 +154,24 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow kicking the owner
- if (member.id === interaction.guild.ownerId) throw "You cannot kick the owner of the server";
+ if (member.id === interaction.guild.ownerId) throw new Error("You cannot kick the owner of the server");
// Check if Nucleus can kick the member
- if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to kick
- if (!me.permissions.has("KICK_MEMBERS")) throw "I do not have the *Kick Members* permission";
+ if (!me.permissions.has("KICK_MEMBERS")) throw new Error("I do not have the *Kick Members* permission");
// Do not allow kicking Nucleus
- if (member.id === interaction.guild.me.id) throw "I cannot kick myself";
+ if (member.id === interaction.guild.me.id) throw new Error("I cannot kick myself");
// Allow the owner to kick anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has kick_members permission
- if (!member.permissions.has("KICK_MEMBERS")) throw "You do not have the *Kick Members* permission";
+ if (!member.permissions.has("KICK_MEMBERS")) throw new Error("You do not have the *Kick Members* permission");
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow kick
return true;
};
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index dc44e5a..151ff76 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -365,24 +365,25 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow muting the owner
- if (member.id === interaction.guild.ownerId) throw "You cannot mute the owner of the server";
+ if (member.id === interaction.guild.ownerId) throw new Error("You cannot mute the owner of the server");
// Check if Nucleus can mute the member
- if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to mute
- if (!me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the *Moderate Members* permission";
+ if (!me.permissions.has("MODERATE_MEMBERS")) throw new Error("I do not have the *Moderate Members* permission");
// Do not allow muting Nucleus
- if (member.id === me.id) throw "I cannot mute myself";
+ if (member.id === me.id) throw new Error("I cannot mute myself");
// Allow the owner to mute anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has moderate_members permission
- if (!member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the *Moderate Members* permission";
+ if (!member.permissions.has("MODERATE_MEMBERS"))
+ throw new Error("You do not have the *Moderate Members* permission");
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow mute
return true;
};
diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts
index cba14f4..c6f0633 100644
--- a/src/commands/mod/nick.ts
+++ b/src/commands/mod/nick.ts
@@ -14,7 +14,7 @@
option.setName("name").setDescription("The name to set | Leave blank to clear").setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { renderUser } = client.logger;
// TODO:[Modals] Replace this with a modal
let notify = true;
@@ -167,24 +167,25 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow any changing of the owner
- if (member.id === interaction.guild.ownerId) throw "You cannot change the owner's nickname";
+ if (member.id === interaction.guild.ownerId) throw new Error("You cannot change the owner's nickname");
// Check if Nucleus can change the nickname
- if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to change the nickname
- if (!me.permissions.has("MANAGE_NICKNAMES")) throw "I do not have the *Manage Nicknames* permission";
+ if (!me.permissions.has("MANAGE_NICKNAMES")) throw new Error("I do not have the *Manage Nicknames* permission");
// Allow the owner to change anyone's nickname
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has manage_nicknames permission
- if (!member.permissions.has("MANAGE_NICKNAMES")) throw "You do not have the *Manage Nicknames* permission";
+ if (!member.permissions.has("MANAGE_NICKNAMES"))
+ throw new Error("You do not have the *Manage Nicknames* permission");
// Allow changing your own nickname
if (member === apply) return true;
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow change
return true;
};
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index 63a919c..24fea75 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -1,5 +1,5 @@
import Discord, { CommandInteraction, GuildChannel, GuildMember, TextChannel } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
@@ -25,7 +25,7 @@
option.setName("reason").setDescription("The reason for the purge").setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const user = (interaction.options.getMember("user") as GuildMember) ?? null;
const channel = interaction.channel as GuildChannel;
if (
@@ -396,11 +396,11 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
// Check if nucleus has the manage_messages permission
- if (!me.permissions.has("MANAGE_MESSAGES")) throw "I do not have the *Manage Messages* permission";
+ if (!me.permissions.has("MANAGE_MESSAGES")) throw new Error("I do not have the *Manage Messages* permission");
// Allow the owner to purge
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has manage_messages permission
- if (!member.permissions.has("MANAGE_MESSAGES")) throw "You do not have the *Manage Messages* permission";
+ if (!member.permissions.has("MANAGE_MESSAGES")) throw new Error("You do not have the *Manage Messages* permission");
// Allow purge
return true;
};
diff --git a/src/commands/mod/slowmode.ts b/src/commands/mod/slowmode.ts
index 5565534..654fbcc 100644
--- a/src/commands/mod/slowmode.ts
+++ b/src/commands/mod/slowmode.ts
@@ -1,6 +1,7 @@
+// @ts-expect-error
import humanizeDuration from "humanize-duration";
-import { CommandInteraction, GuildMember, TextChannel } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { CommandInteraction, GuildMember, TextChannel } from "discord.js";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import keyValueList from "../../utils/generateKeyValueList.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@@ -91,9 +92,9 @@
const member = interaction.member as GuildMember;
// Check if Nucleus can set the slowmode
if (!interaction.guild.me.permissions.has("MANAGE_CHANNELS"))
- throw "I do not have the *Manage Channels* permission";
+ throw new Error("I do not have the *Manage Channels* permission");
// Check if the user has manage_channel permission
- if (!member.permissions.has("MANAGE_CHANNELS")) throw "You do not have the *Manage Channels* permission";
+ if (!member.permissions.has("MANAGE_CHANNELS")) throw new Error("You do not have the *Manage Channels* permission");
// Allow slowmode
return true;
};
diff --git a/src/commands/mod/softban.ts b/src/commands/mod/softban.ts
index 57a70dc..67ecdd6 100644
--- a/src/commands/mod/softban.ts
+++ b/src/commands/mod/softban.ts
@@ -20,7 +20,7 @@
.setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { renderUser } = client.logger;
// TODO:[Modals] Replace this with a modal
let reason = null;
@@ -145,24 +145,24 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow softbanning the owner
- if (member.id === interaction.guild.ownerId) throw "You cannot softban the owner of the server";
+ if (member.id === interaction.guild.ownerId) throw new Error("You cannot softban the owner of the server");
// Check if Nucleus can ban the member
- if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to ban
- if (!me.permissions.has("BAN_MEMBERS")) throw "I do not have the *Ban Members* permission";
+ if (!me.permissions.has("BAN_MEMBERS")) throw new Error("I do not have the *Ban Members* permission");
// Do not allow softbanning Nucleus
- if (member.id === me.id) throw "I cannot softban myself";
+ if (member.id === me.id) throw new Error("I cannot softban myself");
// Allow the owner to softban anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has ban_members permission
- if (!member.permissions.has("BAN_MEMBERS")) throw "You do not have the *Ban Members* permission";
+ if (!member.permissions.has("BAN_MEMBERS")) throw new Error("You do not have the *Ban Members* permission");
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow softban
return true;
};
diff --git a/src/commands/mod/unban.ts b/src/commands/mod/unban.ts
index 9ba10e1..81a29a2 100644
--- a/src/commands/mod/unban.ts
+++ b/src/commands/mod/unban.ts
@@ -13,7 +13,7 @@
option.setName("user").setDescription("The user to unban (Username or ID)").setRequired(true)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const bans = await interaction.guild.bans.fetch();
const user = interaction.options.getString("user");
let resolved = bans.find((ban) => ban.user.id === user);
@@ -110,11 +110,11 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
// Check if Nucleus can unban members
- if (!me.permissions.has("BAN_MEMBERS")) throw "I do not have the *Ban Members* permission";
+ if (!me.permissions.has("BAN_MEMBERS")) throw new Error("I do not have the *Ban Members* permission");
// Allow the owner to unban anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has ban_members permission
- if (!member.permissions.has("BAN_MEMBERS")) throw "You do not have the *Ban Members* permission";
+ if (!member.permissions.has("BAN_MEMBERS")) throw new Error("You do not have the *Ban Members* permission");
// Allow unban
return true;
};
diff --git a/src/commands/mod/unmute.ts b/src/commands/mod/unmute.ts
index 40a2093..18363d5 100644
--- a/src/commands/mod/unmute.ts
+++ b/src/commands/mod/unmute.ts
@@ -11,7 +11,7 @@
.setDescription("Unmutes a user")
.addUserOption((option) => option.setName("user").setDescription("The user to unmute").setRequired(true));
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { log, NucleusColors, renderUser, entry, renderDelta } = client.logger;
// TODO:[Modals] Replace this with a modal
let reason = null;
@@ -63,7 +63,7 @@
}
const member = interaction.options.getMember("user") as GuildMember;
try {
- member.timeout(0, reason || "No reason provided");
+ member.timeout(0, reason ?? "No reason provided");
} catch {
await interaction.editReply({
embeds: [
@@ -134,22 +134,23 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow unmuting the owner
- if (member.id === interaction.guild.ownerId) throw "You cannot unmute the owner of the server";
+ if (member.id === interaction.guild.ownerId) throw new Error("You cannot unmute the owner of the server");
// Check if Nucleus can unmute the member
- if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to unmute
- if (!me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the *Moderate Members* permission";
+ if (!me.permissions.has("MODERATE_MEMBERS")) throw new Error("I do not have the *Moderate Members* permission");
// Allow the owner to unmute anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has moderate_members permission
- if (!member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the *Moderate Members* permission";
+ if (!member.permissions.has("MODERATE_MEMBERS"))
+ throw new Error("You do not have the *Moderate Members* permission");
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow unmute
return true;
};
diff --git a/src/commands/mod/viewas.ts b/src/commands/mod/viewas.ts
index 577192f..1120f72 100644
--- a/src/commands/mod/viewas.ts
+++ b/src/commands/mod/viewas.ts
@@ -159,7 +159,7 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
- if (!member.permissions.has("MANAGE_ROLES")) throw "You do not have the *Manage Roles* permission";
+ if (!member.permissions.has("MANAGE_ROLES")) throw new Error("You do not have the *Manage Roles* permission");
return true;
};
diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts
index 5e321d0..87e6e07 100644
--- a/src/commands/mod/warn.ts
+++ b/src/commands/mod/warn.ts
@@ -12,7 +12,7 @@
.setDescription("Warns a user")
.addUserOption((option) => option.setName("user").setDescription("The user to warn").setRequired(true));
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { log, NucleusColors, renderUser, entry } = client.logger;
// TODO:[Modals] Replace this with a modal
let reason = null;
@@ -286,17 +286,18 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null) throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow warning bots
- if (member.user.bot) throw "I cannot warn bots";
+ if (member.user.bot) throw new Error("I cannot warn bots");
// Allow the owner to warn anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has moderate_members permission
- if (!member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the *Moderate Members* permission";
+ if (!member.permissions.has("MODERATE_MEMBERS"))
+ throw new Error("You do not have the *Moderate Members* permission");
// Check if the user is below on the role list
- if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow warn
return true;
};