I’m trying to make this command so only I can run it, no luck so far.
JavaScript
x
10
10
1
client.on("message", message => {
2
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
3
const command = args.shift().toLowerCase()
4
5
if (command === "test") {
6
console.log((chalk.yellow)`You ran a command: test`)
7
message.channel.send('test')
8
}
9
});
10
I tried using
JavaScript
1
2
1
if (!message.author.id === config.ownerID) return;
2
and
JavaScript
1
2
1
if (message.author.id !== config.ownerID) return;
2
When I used the first one, the command worked but everyone was able to run it, and when I used the second one no one was able to run it at all. I don’t get any error logs nor crashes. Anyone knows the correct code?
Advertisement
Answer
As I mentioned in my comment above, the first one is definitely incorrect, as you’re converting message.author.id
to a boolean by using the logical NOT operator (!
). Your second attempt could work if config.ownerID
was a string, but you can’t compare a string to an array.
If your config.ownerID
is an array of IDs, you can use the includes()
method to check if the message.author.id
is included the given array:
JavaScript
1
2
1
if (config.ownerID.includes(message.author.id)) return
2