Home > front end >  is it possible to get guild owner tag in discord.js v13?
is it possible to get guild owner tag in discord.js v13?

Time:08-03

i tried

const ownerId = guild.fetchOwner();
console.log(ownerId.tag)

i get undefined same thing when im evaluating it message.guild.ownerId.tag

list of testing eval

  1. message.guild.ownertag = undefined
  2. message.guild.ownerTag = undefined
  3. message.guild.owner.tag = undefined
  4. message.guild.owner.Tag = undefined
  5. message.guild.ownerId.tag = undefined
  6. message.guild.ownerId.Tag = undefined
  7. message.guild.ownerId = (my_id/guild_owner_id)
  8. message.guild.fetchOwner() = (<@my_id>/<@guild_owner_ID>)

please help me out

CodePudding user response:

guild.fetchOwner() returns a promise, you need to add await.

const ownerId = await guild.fetchOwner();
// also, you need to access the user property before trying to get the user tag
console.log(ownerId.user.tag);

CodePudding user response:

There is also another way to fetch the owner if you want to do it synchronously. You can use guild.ownerId to get the id of the owner and then guild.members.cache.get() to get the owner. An example:

const ownerId = guild.ownerId
const owner = guild.members.cache.get(ownerId)
console.log(owner.user.tag)

(Note: the owner might not be cached sometimes so guild.members.cache.get() might not return anything sometimes. I just posted this as an alternative to @Crytek1012's answer)

  • Related