This snippet sets the nickname of the user who was mentioned in the first option of the slash command to the nickname which was passed as the second option of the slash command. Remember to register a slash command named "/nickname" via the [command builder](https://autocode.com/tools/discord/command-builder/) with a required `User` option named `user` and a required `String` option named `nick`. You must also have privileged intents enabled for your bot.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let event = context.params.event;
let adminRole = process.env.ADMIN_ROLE;
let user = event.data.options[0].value;
let nick = event.data.options[1].value;
if (context.params.event.member.roles.includes(adminRole)) {
await lib.discord.guilds['@0.1.0'].members.update({
user_id: user,
guild_id: event.guild_id,
nick: nick,
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: event.channel_id,
content: `<@${user}>'s nickname was changed to \`${nick}\` by <@${event.member.user.id}>`,
});
} else {
await lib.discord.users['@0.1.5'].dms.create({
recipient_id: event.member.user.id,
content: `Hey ${event.member.user.username}! You don't have the permission to use the command \`/nick\`.`,
});
}
// Commands Logs
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: process.env.CMDLOGS_CHANNEL,
content: `Command Usage`,
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: '',
color: 0x0dedcf,
fields: [
{
name: `Author`,
value: `<@${event.member.user.id}>`,
},
{
name: `Channel`,
value: `<#${event.channel_id}>`,
},
{
name: `Command`,
value: `/nick`,
},
],
},
],
});