如何在Node.Js和Discord.Js中设置一个TypoError以使bot加入语音通道



晚上好!我正在开发一个音乐Bot Discord在Javascript与Node.Js,我有这个问题:

这里是"play"命令,但是我在所有要求加入语音通道的命令中都会遇到这个问题。

typoerror

语音编码:

module.exports = {
name: 'play',
aliases: ['p'],
category: 'Music',
utilisation: '{prefix}play [name/URL]',
execute(client, message, args) {
if (!message.member.channel) return message.channel.send(`${client.emotes.error} - T'es pas dans le channel vocal !`);

if (!args[0]) return message.channels.send(`${client.emotes.error} - Indique le nom de la musique!`);
client.player.play(message, args.join(" "), { firstResult: true });
},
};

const { Client, Intents, MessageManager, Message, DiscordAPIError } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '-';
const fs = require('fs');
const Discord = require('discord.js');
client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => { 
console.log('Troubadour is online!');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'play'){
client.commands.get('play').execute(message, args);

AGuildMember没有channel属性。您可能想使用GuildMember.voice.channel:

if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - T'es pas dans le channel vocal !`);

注意:您可能需要检查命令是否来自公会,使用如下命令:

  • if (!message.member?.voice.channel)
    
  • if (message.member && !message.member.voice.channel)
    

最新更新