Magixxz
Magixxz

Reputation: 41

How can you check if the person using the command is the owner?

I want the bot to reply with "You can't warn the owner!", but I can't seem to get the right code. Here is a snippet of my code:

let id = '328248785933434881'
let ownerID = client.users.fetch(id);

if (message.mentions.has(ownerID))
  return message.channel.reply(`<@${message.author.id}>, you can\'t warn the owner...`);

Upvotes: 0

Views: 247

Answers (2)

Magixxz
Magixxz

Reputation: 41

Found the solution. Works the same as what I was asking for, except it only works for single / personal servers instead of global bots.

const ownerID = 'OWNERS ID'
    if (message.mentions.has(ownerID)) return (message.channel.send(`You aren't allowed to warn <@${ownerID}>!`))

Upvotes: 0

Pentium1080Ti
Pentium1080Ti

Reputation: 1056

You can get the owner of a server by searching the guild by the ID, like this:

let guild = client.guilds.cache.get('GuildID');
console.log(guild.ownerID);

But if you want to skip extracting the ID from the mention and comparing it to ownerID then you can compare users like this:

let guild = client.guilds.cache.get('GuildID');
if (message.mentions.has(guild.owner))
  return message.channel.send(`<@${message.author.id}>, you can\'t warn the owner...`);

Upvotes: 1

Related Questions