Reputation: 173
I am implementing audit logs in my bot.
I want to ask, if its possible to check for multiple channel names.
const logs = message.guild.channels.cache.find(channel => channel.name === "logs");
if (message.guild.me.hasPermission('MANAGE_CHANNELS') && !logs) {
message.guild.channels.create('logs', { type: 'text' });
I am using this to check if a log channel exists, but if not, the bot will create one.
I want to add more channel names, because some servers dont have the same name for logs channel.
Upvotes: 0
Views: 449
Reputation: 2023
I think what you are asking is how to search for multiple names e.g. logs
or bot-log
for example. All you need to do is use the OR operator (||) like this:
const logs = message.guild.channels.cache.find(channel => channel.name === "logs" || channel.name === "bot-log");
These operators work in many circumstances e.g. if statements
let foo = 'foo'
let bar = 'bar'
if (foo === 'foo' && bar === 'foo') return //this will never call - the && operator means 'AND'
if (foo === 'foo' || bar === 'foo') return //this WILL call - the || operator means 'OR'
Upvotes: 1