0

I have a command in which one user virtually kisses another

The output is a message @User1 kissed @User2

But I want that instead of tags on the user, only names were written, like this so that it was user1 kissed user2

In theory, everything should work like this

`**${message.author.username}** kissed **${userToKiss.username}**`

But if the name for message.author is defined, then there is none for userToKiss and I end up with this

user1 kissed undefined

How can I get the name for the second user?

const { Command } = require('discord.js-commando');
const Discord = require('discord.js');

module.exports = class KissCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'kiss',
      memberName: 'kiss',
      group: 'reywl',
      description: 'Kiss the mentioned user',
      guildOnly: true,
      args: [
        {
          key: 'userToKiss',
          prompt: 'Please select the member you want to kiss.',
          type: 'member',
          default: 'isempty',
          wait: 0.0001
        }
      ]
    });
  }
  
  run(message, { userToKiss }) {
    if (userToKiss == 'isempty') {
        return message.channel.send('Please select the member you want to kiss.')}
    if (userToKiss.id == message.author.id) {
      return message.channel.send('You cant kiss yourself!');
    }
    else {
        const embed = new Discord.MessageEmbed()
        .setDescription(`**${message.author}** kissed **${userToKiss}**`)

        message.channel.send(embed)
    }
    setTimeout(() => message.delete(), 1000)
}};
  • the person (user2) that is entered in the command, will turn into the guild member's ID number. then you can use a guild.members.fetch(user2ID), and get the guild member object, and then extract the name from there – G-Force Apr 01 '22 at 14:54
  • @G-Force I don't understand how to do it, I get an error `An error occurred while running the command: ReferenceError: guild is not defined` –  Apr 01 '22 at 14:59
  • @G-Force this is how it works `const kissed = message.guild.members.fetch(userToKiss.id)` but how can I get the username from there now? like this doesn't work `${kissed.username}` –  Apr 01 '22 at 15:23
  • remember that there is a difference between GuildMember object and User. A GuildMember object has somethin called displayName (handy as it covers both the name and nickname cases) and a User has username property. – G-Force Apr 08 '22 at 01:59

2 Answers2

0

This is how it works

const kissed = await message.guild.members.fetch(userToKiss.id);

${kissed.user.username}
0

For deep explanation for your work, to do this you need to code first about the member, we always do about member and author

Author is for the author itself and the member for your members who are you going to call

I don't know if commando and normal command handlers are the same but here's the code what you wanted.

const member = message.mentions.members.first() //this is the way how you ping a member
${member.user.username} //the word user is the user member

for the author you can only do this

${message.author.username}

You can also ping a member using their Id's

const member = message.guild.members.cache.get(args[0])
${member.user.username}

So the main output is

${message.author.username} kissed ${member.user.username}
新Acesyyy
  • 1,152
  • 1
  • 3
  • 22