【问题标题】: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每当我尝试启动我的不和谐机器人时,我都会收到一条错误消息,上面写着 ReferenceError: client is not defined,因此我的机器人不会启动
【发布时间】:2021-03-28 13:45:57
【问题描述】:

我有

const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); for(命令文件的常量文件){ const 命令 = 要求(./commands/${file});

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

}

cleint.once('准备好了', () => { console.log('KindnessBot 上线了!'); cleint.user.setActivity('使用 !help 获取命令列表,由 Keaton8legs', { type: 'WATCHING' }).catch(console.error); });

cleint.on('消息', 消息 =>{ 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 = { 名称:'平', description: "这是一个 ping 命令!", 执行(消息,参数){ message.channel.send('pong!');
} }

【问题讨论】:

  • 请花点时间学习如何正确格式化您的问题。这将使其更有可能得到答案。

标签: javascript discord client bots


【解决方案1】:

client 没有定义,需要定义为 Discord.Client 的实例,如:

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

【讨论】:

  • const Discord = require('discord.js'); const cleint = new Discord.Client();
  • 您似乎将client 拼错为cleint
【解决方案2】:

你还没有定义客户端

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

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 2022-11-15
    • 2021-11-24
    • 1970-01-01
    • 2020-08-29
    • 2021-11-16
    相关资源
    最近更新 更多