bobby the pikachu
bobby the pikachu

Reputation: 33

discord.js how to get a Discord username from a user ID

im programming a Discord bot and I would like to get Discord usernames from user IDs so I know who voted for my bot ive I've tried that using Google to find the answer but it doesn't really show me

Upvotes: 2

Views: 4372

Answers (1)

Dorian349
Dorian349

Reputation: 1589

You need to collect the user from your client.

const Discord = require("discord.js");
const client = new Discord.Client();

//This return the username of the specified user ID.
const user = client.users.cache.get("USERID");
if (!user) return console.log("Couldn't find the user");
console.log(user.username)

Upvotes: 3

Related Questions