Tickets! and a lot of bug fixes
diff --git a/src/commands/role/user.ts b/src/commands/role/user.ts
index ac94b47..ad29811 100644
--- a/src/commands/role/user.ts
+++ b/src/commands/role/user.ts
@@ -1,5 +1,5 @@
-import { CommandInteraction, GuildMember, Role } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { CommandInteraction, GuildMember, Role, User } from "discord.js";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import client from "../../utils/client.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import keyValueList from "../../utils/generateKeyValueList.js";
@@ -28,79 +28,68 @@
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { renderUser, renderRole } = client.logger;
- const action = interaction.options.getString("action");
+ const action = interaction.options.get("action")?.value as string;
+ const role: Role = (await interaction.guild!.roles.fetch(interaction.options.get("role")?.value as string))!;
// TODO:[Modals] Replace this with a modal
const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.ROLES.DELETE")
.setTitle("Role")
.setDescription(
keyValueList({
- user: renderUser(interaction.options.getUser("user")),
- role: renderRole(interaction.options.get("role"))
+ user: renderUser(interaction.options.getUser("user")! as User),
+ role: renderRole(role)
}) +
`\nAre you sure you want to ${
action === "give" ? "give the role to" : "remove the role from"
} ${interaction.options.getUser("user")}?`
)
.setColor("Danger")
+ .setFailedMessage("No changes were made", "Success", "GUILD.ROLES.CREATE")
.send();
- if (confirmation.cancelled) return;
- if (confirmation.success) {
- try {
- const member = interaction.options.getMember("user") as GuildMember;
- const role = interaction.options.get("role") as unknown as Role;
- if (interaction.options.getString("action") === "give") {
- member.roles.add(role);
- } else {
- member.roles.remove(role);
- }
- } catch (e) {
- return await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Role")
- .setDescription("Something went wrong and the role could not be added")
- .setStatus("Danger")
- .setEmoji("CONTROL.BLOCKCROSS")
- ],
- components: []
- });
+ if (confirmation.cancelled || !confirmation.success) return;
+ try {
+ const member = interaction.options.getMember("user") as GuildMember;
+ if ((interaction.options.get("action")?.value as string) === "give") {
+ member.roles.add(role);
+ } else {
+ member.roles.remove(role);
}
+ } catch (e) {
return await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Role")
- .setDescription(`The role has been ${action === "give" ? "given" : "removed"} successfully`)
- .setStatus("Success")
- .setEmoji("GUILD.ROLES.CREATE")
- ],
- components: []
- });
- } else {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("GUILD.ROLES.CREATE")
- .setTitle("Role")
- .setDescription("No changes were made.")
+ .setDescription("Something went wrong and the role could not be added")
.setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
],
components: []
});
}
+ return await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Role")
+ .setDescription(`The role has been ${action === "give" ? "given" : "removed"} successfully`)
+ .setStatus("Success")
+ .setEmoji("GUILD.ROLES.CREATE")
+ ],
+ components: []
+ });
};
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
- const me = interaction.guild.me!;
+ if (!interaction.guild) return
+ const me = interaction.guild.members.me!;
const apply = interaction.options.getMember("user") as GuildMember | null;
- if (apply === null) throw new Error("That member is not in the server");
+ if (apply === null) return "That member is not in the server";
// Check if Nucleus has permission to role
- if (!me.permissions.has("MANAGE_ROLES")) throw new Error("I do not have the *Manage Roles* permission");
+ if (!me.permissions.has("ManageRoles")) return "I do not have the *Manage Roles* permission";
// Allow the owner to role anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has manage_roles permission
- if (!member.permissions.has("MANAGE_ROLES")) throw new Error("You do not have the *Manage Roles* permission");
+ if (!member.permissions.has("ManageRoles")) return "You do not have the *Manage Roles* permission";
// Allow role
return true;
};