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

Viewed 3674

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

1 Answers

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)
Related