How To Return A Guild's Owner Name
This is the piece of my code where I'm having the problem: const guild = client.guilds.get('500170876243935247'); message.channel.send(guild.owner); I expected it to return the ow
Solution 1:
When you convert a User to a string, the User.toString()
method is automatically called: that converts the User object into a mention, like @username. But if you do message.channel.send(User)
it will not call User.toString()
and so discord.js will be left with an object that it can't send (example for valid object: message.channel.send(
RichEmbed
)
), and so the message will be empty.
To avoid this, you can try to replace the mention with something like User.tag
: with this you also avoid being notified every time someone uses that command.
If you don't mind being notified you can use the first one when possible, otherwise the second one. Here's an example:
const guild = client.guilds.get('500170876243935247');
message.channel.send(message.guild.member(guild.owner) ? guild.owner.toString() : guild.owner.user.tag);
// if the user is in that guild it will mention him, otherwise it will use .tag
Solution 2:
client.on('message', msg => {
const thisguild = msg.guild;
const owner = thisguild.owner.user.username;
}
Post a Comment for "How To Return A Guild's Owner Name"