-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Added nickname command which allows you to change your own nick…
…name or others!
- Loading branch information
Showing
1 changed file
with
87 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,87 @@ | ||
const { SlashCommandBuilder } = require("@discordjs/builders"); | ||
const { Permissions } = require("discord.js"); | ||
const { embedMessage } = require("../../modules/embedSimple"); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName("nickname") | ||
.setDescription("Changes your own nickname or other user's") | ||
.addStringOption((option) => | ||
option | ||
.setName("nick") | ||
.setDescription("The new nickname!") | ||
.setRequired(true) | ||
) | ||
.addUserOption((option) => | ||
option | ||
.setName("user") | ||
.setDescription("Select a user to change their's nickname") | ||
), | ||
async execute(interaction, client) { | ||
await interaction.deferReply(); | ||
|
||
const user = interaction.options.getMember("user"); | ||
const newNickname = interaction.options.getString("nick"); | ||
|
||
if ( | ||
user && | ||
!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_NICKNAMES) | ||
) { | ||
await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`You do not have permission to change ${user.toString()} nickname!` | ||
), | ||
], | ||
}); | ||
} | ||
|
||
if ( | ||
user && | ||
interaction.member.permissions.has(Permissions.FLAGS.MANAGE_NICKNAMES) | ||
) { | ||
try { | ||
await user.setNickname(newNickname); | ||
await interaction.followUp({ | ||
embeds: [ | ||
embedMessage("#9dcc37", `Nickname has been successfully changed!`), | ||
], | ||
}); | ||
} catch (err) { | ||
if (err.message === "Missing Permissions") { | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ I do not have permission to change other member's nicknames who have the same role as me or higher!` | ||
), | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
|
||
if (!user) { | ||
try { | ||
await interaction.member.setNickname(newNickname); | ||
await interaction.followUp({ | ||
embeds: [ | ||
embedMessage("#9dcc37", `Nickname has been successfully changed!`), | ||
], | ||
}); | ||
} catch (err) { | ||
if (err.message === "Missing Permissions") { | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
` ❌ I do not have permission to change your Nickname, maybe your role is higher than mine or perhaps you are the owner ?` | ||
), | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
}; |