-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let extended team members rename oaf
- Loading branch information
1 parent
b4a23e4
commit f3241e5
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
})); | ||
} | ||
} |