0

我目前正在编写一个discord.js机器人,我做了这个join命令,所以机器人可以加入我的语音频道

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();
}

问题是我不知道如何制作它,以便如果最后一个函数出错或根本不起作用它可以向用户发送错误消息,例如 @User, I could not join the channel, "THE ERROR":/我不希望我的机器人崩溃并且仅仅因为一个小细节就不得不再次运行它。有没有办法解决它?这对我有很大帮助!提前致谢!

4

1 回答 1

0

我不会让用户知道这个错误,因为它可能会让他们感到困惑,但你可以try catch检查它是否通过,如果没有发送消息。

try {
      membervc.join();
} catch(error){
      console.log(error);
      message.reply(`Something went wrong while joining voice channel`);
}
于 2021-09-26T20:32:16.000 回答