Home > Blockchain >  My bot can't take errors when failling to run a "join" voice channel command
My bot can't take errors when failling to run a "join" voice channel command

Time:09-27

I'm currently coding a discord.js bot and I made this join command so the bot can join my voice channel

module.exports.run = async (client, message, args) => {

let membervc = message.member.voice.channel;
let botvc = message.guild.me.voice.channel;
if(!membervc) return message.send('You need to join a voice channel first.');
if(botvc){
    if(!(botvc.members.size - 1)) return message.reply(`I am already on ${botvc}`);
    if(membervc.id == botvc.id) return message.reply('We are already on the same voice channel.');
};
membervc.join();
}

The problem is that I have no idea how to make it so that if the last function gets an error or doesn't work at all It can send an error message to the user like @User, I could not join the channel, "THE ERROR" :/ I don't want my bot to crash and having to run it again just because of one small detail. Is there a way to fix it? It would help me a lot! Thanks in advance!

CodePudding user response:

I would not let the user know about the error, because it might just confuse them, but you can do try catch to check if it goes through and if not message is sent.

try {
      membervc.join();
} catch(error){
      console.log(error);
      message.reply(`Something went wrong while joining voice channel`);
}
  • Related