I made a function that supposed to return a role member count but it returns "undefined".
Here's my code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', (message) => {
argument = message.content.split(' ');
switch (argument[0]) {
case 'showmember':
let membercount = (therole) => {
let role = message.guild.roles.cache.find(r => r.name === therole);
message.guild.members.fetch().then(fetched => {
let total = fetched.filter(m => m.roles.cache.some(r => r === role));
return total.length;
});
};
message.channel.send(membercount(argument.join(',').slice('showmember'.length)));
break;
}
}
This is what it says on the console (node:133436) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message