Skip to content

Commit

Permalink
let extended team members rename oaf
Browse files Browse the repository at this point in the history
  • Loading branch information
horrible-little-slime committed Dec 1, 2023
1 parent b4a23e4 commit f3241e5
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/commands/misc/rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
ChatInputCommandInteraction,
GuildMemberRoleManager,
SlashCommandBuilder,
} from "discord.js";

import { discordClient } from "../../clients/discord.js";
import { config } from "../../config.js";

export const data = new SlashCommandBuilder()
.setName("rename")
.setDescription("Renames our beloved O.A.F.")
.addStringOption((o) =>
o
.setName("name")
.setDescription("Our beloved O.A.F.'s new name")
.setRequired(true),
);

export async function execute(interaction: ChatInputCommandInteraction) {
const member = interaction.member;

if (!member) {
interaction.reply({
content: "You have to perform this action from within a Guild.",
ephemeral: true,
});
return;
}

const roleManager = member.roles as GuildMemberRoleManager;

if (!roleManager.cache.has(config.EXTENDED_TEAM_ROLE_ID)) {
interaction.reply({
content: "You are not permitted to rename me, your beloved O.A.F.",
ephemeral: true,
});
return;
}

const name = interaction.options.getString("name", true);
await discordClient.user?.setUsername(name);

if (discordClient.user?.username === name) {
return void (await interaction.reply({
content: `Done! My name is now ${name}`,
ephemeral: true,
}));
} else {
discordClient.alert(
`${interaction.user.username} tried to change O.A.F.'s name to ${name}, but failed!`,
);
return void (await interaction.reply({
content: "Sorry, that command didn't work. My name is still my name.",
ephemeral: true,
}));
}
}

0 comments on commit f3241e5

Please sign in to comment.