styling fixes and some typing
diff --git a/src/commands/settings/commands.ts b/src/commands/settings/commands.ts
index 19a13e3..fe6a181 100644
--- a/src/commands/settings/commands.ts
+++ b/src/commands/settings/commands.ts
@@ -15,7 +15,7 @@
.setDescription("Links and text shown to a user after a moderator action is performed")
.addRoleOption((o) => o.setName("role").setDescription("The role given when a member is muted"));
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
await interaction.reply({
embeds: LoadingEmbed,
ephemeral: true,
@@ -218,7 +218,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};
diff --git a/src/commands/settings/filters.ts b/src/commands/settings/filters.ts
index 3b0988e..1a297ca 100644
--- a/src/commands/settings/filters.ts
+++ b/src/commands/settings/filters.ts
@@ -11,7 +11,7 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_MESSAGES"))
- throw "You must have the *Manage Messages* permission to use this command";
+ throw new Error("You must have the *Manage Messages* permission to use this command");
return true;
};
diff --git a/src/commands/settings/logs/attachment.ts b/src/commands/settings/logs/attachment.ts
index 8e72651..52fdd5f 100644
--- a/src/commands/settings/logs/attachment.ts
+++ b/src/commands/settings/logs/attachment.ts
@@ -20,7 +20,7 @@
.setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const m = (await interaction.reply({
embeds: LoadingEmbed,
ephemeral: true,
@@ -191,7 +191,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};
diff --git a/src/commands/settings/logs/channel.ts b/src/commands/settings/logs/channel.ts
index 21437b2..c645581 100644
--- a/src/commands/settings/logs/channel.ts
+++ b/src/commands/settings/logs/channel.ts
@@ -19,7 +19,7 @@
.addChannelTypes([ChannelType.GuildNews, ChannelType.GuildText])
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const m = (await interaction.reply({
embeds: LoadingEmbed,
ephemeral: true,
@@ -185,7 +185,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};
diff --git a/src/commands/settings/logs/events.ts b/src/commands/settings/logs/events.ts
index a2dcc63..c3fbe41 100644
--- a/src/commands/settings/logs/events.ts
+++ b/src/commands/settings/logs/events.ts
@@ -117,7 +117,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};
diff --git a/src/commands/settings/logs/staff.ts b/src/commands/settings/logs/staff.ts
index 8450bbb..715fbea 100644
--- a/src/commands/settings/logs/staff.ts
+++ b/src/commands/settings/logs/staff.ts
@@ -21,7 +21,7 @@
.setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<unknown | void> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (!interaction.guild) return;
const m = (await interaction.reply({
embeds: LoadingEmbed,
@@ -190,7 +190,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};
diff --git a/src/commands/settings/rolemenu.ts b/src/commands/settings/rolemenu.ts
index 93fe70d..b9464b5 100644
--- a/src/commands/settings/rolemenu.ts
+++ b/src/commands/settings/rolemenu.ts
@@ -16,7 +16,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_ROLES"))
- throw "You must have the *Manage Roles* permission to use this command";
+ throw Error("You must have the *Manage Roles* permission to use this command");
return true;
};
diff --git a/src/commands/settings/stats.ts b/src/commands/settings/stats.ts
index 08bf6f8..b4bca10 100644
--- a/src/commands/settings/stats.ts
+++ b/src/commands/settings/stats.ts
@@ -21,7 +21,7 @@
.setAutocomplete(true)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
singleNotify("statsChannelDeleted", interaction.guild.id, true);
const m = (await interaction.reply({
embeds: LoadingEmbed,
@@ -219,7 +219,7 @@
const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_CHANNELS"))
- throw "You must have the *Manage Channels* permission to use this command";
+ throw new Error("You must have the *Manage Channels* permission to use this command");
return true;
};
diff --git a/src/commands/settings/tickets.ts b/src/commands/settings/tickets.ts
index 3c6515d..8b84770 100644
--- a/src/commands/settings/tickets.ts
+++ b/src/commands/settings/tickets.ts
@@ -21,7 +21,7 @@
import { toHexInteger, toHexArray, tickets as ticketTypes } from "../../utils/calculate.js";
import { capitalize } from "../../utils/generateKeyValueList.js";
import { modalInteractionCollector } from "../../utils/dualCollector.js";
-import { GuildConfig } from "../../utils/database.js";
+import type { GuildConfig } from "../../utils/database.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
@@ -60,7 +60,7 @@
.setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
let m = (await interaction.reply({
embeds: LoadingEmbed,
ephemeral: true,
@@ -75,9 +75,9 @@
if (options.enabled !== null || options.category || options.maxtickets || options.supportping) {
options.enabled = options.enabled === "yes" ? true : false;
if (options.category) {
- let channel: GuildChannel;
+ let channel: GuildChannel | null;
try {
- channel = await interaction.guild.channels.fetch(options.category.id);
+ channel = await interaction.guild!.channels.fetch(options.category.id);
} catch {
return await interaction.editReply({
embeds: [
@@ -89,8 +89,9 @@
]
});
}
+ if (!channel) return;
channel = channel as Discord.CategoryChannel;
- if (channel.guild.id !== interaction.guild.id)
+ if (channel.guild.id !== interaction.guild!.id)
return interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -113,10 +114,10 @@
]
});
}
- let role: Role;
+ let role: Role | null;
if (options.supportping) {
try {
- role = await interaction.guild.roles.fetch(options.supportping.id);
+ role = await interaction.guild!.roles.fetch(options.supportping.id);
} catch {
return await interaction.editReply({
embeds: [
@@ -128,8 +129,9 @@
]
});
}
+ if (!role) return;
role = role as Discord.Role;
- if (role.guild.id !== interaction.guild.id)
+ if (role.guild.id !== interaction.guild!.id)
return interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -162,13 +164,13 @@
.send(true);
if (confirmation.cancelled) return;
if (confirmation.success) {
- const toUpdate = {};
+ const toUpdate: Record<string, string | boolean | number> = {};
if (options.enabled !== null) toUpdate["tickets.enabled"] = options.enabled;
if (options.category) toUpdate["tickets.category"] = options.category.id;
if (options.maxtickets) toUpdate["tickets.maxTickets"] = options.maxtickets;
if (options.supportping) toUpdate["tickets.supportRole"] = options.supportping.id;
try {
- await client.database.guilds.write(interaction.guild.id, toUpdate);
+ await client.database.guilds.write(interaction.guild!.id, toUpdate);
} catch (e) {
return interaction.editReply({
embeds: [
@@ -194,7 +196,7 @@
});
}
}
- let data = await client.database.guilds.read(interaction.guild.id);
+ let data = await client.database.guilds.read(interaction.guild!.id);
data.tickets.customTypes = (data.tickets.customTypes || []).filter(
(value: string, index: number, array: string[]) => array.indexOf(value) === index
);
@@ -280,19 +282,19 @@
if ((i.component as MessageActionRowComponent).customId === "clearCategory") {
if (lastClicked === "cat") {
lastClicked = "";
- await client.database.guilds.write(interaction.guild.id, null, ["tickets.category"]);
+ await client.database.guilds.write(interaction.guild!.id, null, ["tickets.category"]);
data.category = undefined;
} else lastClicked = "cat";
} else if ((i.component as MessageActionRowComponent).customId === "clearMaxTickets") {
if (lastClicked === "max") {
lastClicked = "";
- await client.database.guilds.write(interaction.guild.id, null, ["tickets.maxTickets"]);
+ await client.database.guilds.write(interaction.guild!.id, null, ["tickets.maxTickets"]);
data.maxTickets = 5;
} else lastClicked = "max";
} else if ((i.component as MessageActionRowComponent).customId === "clearSupportPing") {
if (lastClicked === "sup") {
lastClicked = "";
- await client.database.guilds.write(interaction.guild.id, null, ["tickets.supportRole"]);
+ await client.database.guilds.write(interaction.guild!.id, null, ["tickets.supportRole"]);
data.supportRole = undefined;
} else lastClicked = "sup";
} else if ((i.component as MessageActionRowComponent).customId === "send") {
@@ -375,12 +377,12 @@
}
if ((i.component as MessageActionRowComponent).customId === "template") {
i.deferUpdate();
- await interaction.channel.send({
+ await interaction.channel!.send({
embeds: [
new EmojiEmbed()
- .setTitle(ticketMessages[parseInt((i as SelectMenuInteraction).values[0])].label)
+ .setTitle(ticketMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.label)
.setDescription(
- ticketMessages[parseInt((i as SelectMenuInteraction).values[0])].description
+ ticketMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.description
)
.setStatus("Success")
.setEmoji("GUILD.TICKET.OPEN")
@@ -398,7 +400,7 @@
break;
} else if ((i.component as MessageActionRowComponent).customId === "blank") {
i.deferUpdate();
- await interaction.channel.send({
+ await interaction.channel!.send({
components: [
new MessageActionRow().addComponents([
new MessageButton()
@@ -456,7 +458,7 @@
try {
out = await modalInteractionCollector(
m,
- (m) => m.channel.id === interaction.channel.id,
+ (m) => m.channel!.id === interaction.channel!.id,
(m) => m.customId === "modify"
);
} catch (e) {
@@ -724,7 +726,7 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};
diff --git a/src/commands/settings/verify.ts b/src/commands/settings/verify.ts
index 614ecb9..0eb4553 100644
--- a/src/commands/settings/verify.ts
+++ b/src/commands/settings/verify.ts
@@ -1,13 +1,14 @@
import { LoadingEmbed } from "./../../utils/defaultEmbeds.js";
import Discord, {
CommandInteraction,
+ Interaction,
Message,
MessageActionRow,
MessageActionRowComponent,
MessageButton,
MessageComponentInteraction,
- MessageEmbed,
MessageSelectMenu,
+ ModalSubmitInteraction,
Role,
SelectMenuInteraction,
TextInputComponent
@@ -15,7 +16,7 @@
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import client from "../../utils/client.js";
import { modalInteractionCollector } from "../../utils/dualCollector.js";
@@ -27,7 +28,7 @@
option.setName("role").setDescription("The role to give after verifying").setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const m = (await interaction.reply({
embeds: LoadingEmbed,
ephemeral: true,
@@ -49,7 +50,7 @@
});
}
role = role as Discord.Role;
- if (role.guild.id !== interaction.guild.id) {
+ if (role.guild.id !== interaction.guild!.id) {
return interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -70,7 +71,7 @@
if (confirmation.cancelled) return;
if (confirmation.success) {
try {
- await client.database.guilds.write(interaction.guild.id, {
+ await client.database.guilds.write(interaction.guild!.id, {
"verify.role": role.id,
"verify.enabled": true
});
@@ -90,7 +91,7 @@
role: entry(role.id, renderRole(role))
},
hidden: {
- guild: interaction.guild.id
+ guild: interaction.guild!.id
}
};
log(data);
@@ -121,7 +122,7 @@
}
}
let clicks = 0;
- const data = await client.database.guilds.read(interaction.guild.id);
+ const data = await client.database.guilds.read(interaction.guild!.id);
let role = data.verify.role;
while (true) {
await interaction.editReply({
@@ -161,7 +162,7 @@
clicks += 1;
if (clicks === 2) {
clicks = 0;
- await client.database.guilds.write(interaction.guild.id, null, ["verify.role", "verify.enabled"]);
+ await client.database.guilds.write(interaction.guild!.id, null, ["verify.role", "verify.enabled"]);
role = undefined;
}
} else if ((i.component as MessageActionRowComponent).customId === "send") {
@@ -241,12 +242,12 @@
}
if ((i.component as MessageActionRowComponent).customId === "template") {
i.deferUpdate();
- await interaction.channel.send({
+ await interaction.channel!.send({
embeds: [
new EmojiEmbed()
- .setTitle(verifyMessages[parseInt((i as SelectMenuInteraction).values[0])].label)
+ .setTitle(verifyMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.label)
.setDescription(
- verifyMessages[parseInt((i as SelectMenuInteraction).values[0])].description
+ verifyMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.description
)
.setStatus("Success")
.setEmoji("CONTROL.BLOCKTICK")
@@ -264,7 +265,7 @@
break;
} else if ((i.component as MessageActionRowComponent).customId === "blank") {
i.deferUpdate();
- await interaction.channel.send({
+ await interaction.channel!.send({
components: [
new MessageActionRow().addComponents([
new MessageButton()
@@ -322,16 +323,20 @@
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) {
break;
}
- if (out.fields) {
+ if (out === null) {
+ continue;
+ } else if (out instanceof ModalSubmitInteraction) {
const title = out.fields.getTextInputValue("title");
const description = out.fields.getTextInputValue("description");
- await interaction.channel.send({
+ await interaction.channel!.send({
embeds: [
new EmojiEmbed()
.setTitle(title)
@@ -369,7 +374,7 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
- throw "You must have the *Manage Server* permission to use this command";
+ throw new Error("You must have the *Manage Server* permission to use this command");
return true;
};