I'm trying to make a say command in a Discord bot where you specify a channel to send the message, and if you don't specify a channel it will send everything after the command(args 1+), otherwise it will send everything after the channel specified(args 2+)
if(command === `${prefix}say`) {
if(!message.member.roles.has(`337402636015894528`)) return;
msg = args.slice(2).join(" ");
let channel = message.mentions.channels.first() || message.guild.channels.find("name", args[1]) || message.channel;
message.delete();
channel.send(msg);
}
This is the code I have, but the problem is that want to check if the user specified a channel, and if not, set msg equal to args.slice(1).join(" "), but I have no idea how to check if the user specified a channel. Does anybody know how? Thanks in advance.
I figured out the solution, thank you all for your help.
let channel = message.mentions.channels.first() || message.guild.channels.find("name", args[1]);
if(!channel) {
channel = message.channel;
msg = args.slice(1).join(" ");
}