Find user by username

Hello.

I was coding a balance command for my bot, and it works well. But I want it to show the balance of other user, but without ping it.

Example:

s!balance
BOT: has X moons.

Anyway to do this?

https://github.com/discordjs/discord.js/issues/539

Still not finding what I’m looking for. That only can be used when you know the username. The thing is: How the hell I can make what I showed in the example’

are you trying to get your own balance? i don’t understand your goal

Getting my balance is easy. I’ve already dons that. But what I want to do is get another user’s balance.

get the mention/id/username from the arguments of the command and use that to fetch the user object. from there get the balance as normal

OK
 But I’m getting some problems, cause I want to use it with mention, id and username only.
How can I do that?

can i see the code you are using right now?

const db = require(‘quick.db’)
const Discord = require(‘discord.js’)

exports.run = async(bot, message, args) => {
let usermon = message.mentions.members.first();

let usermoons = await db.fetch(moons_${message.author.id})

if(!usermon){
message.channel.send(<a:economia:580518832792272916> **|** > ${message.author.username}, vocĂȘ possui **${usermoons}** moons.)

} else {

let membermoons = await db.fetch(`moons_${usermon.id}`)

let membubebed = new Discord.RichEmbed()
.setAuthor(usermon.displayName)
.setThumbnail(usermon.user.avatarURL)
.setColor("RANDOM")
.addField(`<:certo:580518832611786753> Possui`, `${membermoons} moons`)

message.channel.send(membubebed)

}
}

module.exports.command = {
name: ‘moons’,
description: ‘Numero de moons que vocĂȘ tem’,
category: “economia”,
usage: ‘moons’,
enabled: true
}

Sorry for the delay. If you change let usermon = message.mentions.members.first();
to let usermon = message.mentions.members.first() || message.guild.members.get(args[0]); it will work with both user id’s and mentioning a user. Adding username into the mix would add several lines of code in my experience and is not reliable anyway because people can change usernames whenever

1 Like

Thanks man! It worked!

1 Like