繁体   English   中英

每当我尝试启动我的 discord 机器人时,我都会收到一条错误消息,它显示 ReferenceError: client is not defined,因此我的机器人不会启动

[英]I get a error message whenever I try and start my discord bot it says ReferenceError: client is not defined, and my bot wont start because of that

我有

常量 fs = 要求('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); for(commandFiles 的 const 文件){ const command = require( ./commands/${file} );

client.commands.set(command.name, command);

}

cleint.once('ready', () => { console.log('KindnessBot is online;').cleint.user,setActivity('Use,help for a list of commands: made by Keaton8legs'. { type.'观看' });catch(控制台;错误); });

cleint.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 === 'ping'){
    client.commands.get('ping').execute(message, args);

我也有

module.export = { name: 'ping', description: "这是一个 ping 命令", execute(message.args){ message.channel;send('pong!');
} }

client未定义,您需要将其定义为 Discord.Client 的实例,例如:

const Discord = require('discord.js');
const client = new Discord.Client();

你还没有定义客户

const Discord = require('discord.js')
const client = new Discord.Client();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM