I’m currently coding a discord.js
bot and I made this join
command so the bot can join my voice channel
JavaScript
x
12
12
1
module.exports.run = async (client, message, args) => {
2
3
let membervc = message.member.voice.channel;
4
let botvc = message.guild.me.voice.channel;
5
if(!membervc) return message.send('You need to join a voice channel first.');
6
if(botvc){
7
if(!(botvc.members.size - 1)) return message.reply(`I am already on ${botvc}`);
8
if(membervc.id == botvc.id) return message.reply('We are already on the same voice channel.');
9
};
10
membervc.join();
11
}
12
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!
Advertisement
Answer
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.
JavaScript
1
7
1
try {
2
membervc.join();
3
} catch(error){
4
console.log(error);
5
message.reply(`Something went wrong while joining voice channel`);
6
}
7