I want to know the code that targets the person who gave the command

Viewed 31

I want to know the code that targets the person who gave the command instead 'message.mentions.members.first();'

I want to create a way to change my nickname by typing a command, but I always have to do an mention

The code consists of this configuration.

module.exports = { name: "nick", async execute(message, args, client) { const member = message.mentions.members.first();

if (!member) return message.reply("Please specify a member!");

const arguments = args.shift(2)

if (!arguments) return message.reply("Please specify a nickname!");

try { const arguments = args.shift(2) member.setNickname(arguments); }catch (error) { console.error(error);

} }, }

2 Answers

If message is the message sent by the user invoking the bot command, you can access the user that sent that message using the .author property on the Message.

Well if you want to get member of the guild (server) use message.member or if you want the user then message.author or message.member.user. To change the nickname you would want to use message.member.setNickname(arguments)

Related