Owner Name and NickName
Closed this issue · 3 comments
I'm trying to load the information from the server and save it to a database. I'm getting information like name, id, urlImage, owner id ... But I want to get the owner's name, and I'm getting a null result. I know that DiscordLight does not store cache. Would there be any other way of obtaining this information?
const Discord = require('discord.js-light');
const client = new Discord.Client({
cacheGuilds: true,
cacheChannels: true,
cacheOverwrites: false,
cacheRoles: true,
cacheEmojis: false,
cachePresences: false
});
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
client.guilds.cache.forEach((value) => {
console.log(value.name); //return Guild Name
console.log(value.id); //return Guild ID
console.log(value.iconURL()); //return urlImage
console.log(value.owner); //return null
console.log(value.ownerID); //return Owner Id
});
});
You need to fetch the owner:
let owner = await client.users.fetch(value.ownerID)
If you dont want to cache the guild owner, you can add false in the second parameter:
let owner = await client.users.fetch(value.ownerID, false)
Then you can get it from owner.username
Thanks, this worked for me, I just changed to get the name of the owner of each server.
It looked like this:
let owner = await value.owner.fetch(value.ownerID)
Congratulations for the incredible work!
If you're gonna use User#fetch then you dont need to pass any parameter, just await value.owner.fetch()
is enough since it already implies the ID contained in the owner. The first parameter is a boolean value for whether or not to bypass the cache when fetching.