不和机器人将不响应,关闭



我刚开始编程一个Discord机器人(我喜欢它),它有响应问题。当我用node main.js启动它时,它正常工作,直到我做-ping之类的事情,它停止工作。

这是我收到的错误:

ReferenceError: clicent is not defined
at Client.<anonymous> (C:UsersEric MüllerDesktopDiscord botMain.js:27:9)       
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:UsersEric MüllerDesktopDiscord botnode_modulesdiscord.jssrcclientactionsMessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:UsersEric MüllerDesktopDiscord botnode_modulesdiscord.jssrcclientwebsockethandlersMESSAGE_CREATE.js:4:32)        
at WebSocketManager.handlePacket (C:UsersEric MüllerDesktopDiscord botnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:UsersEric MüllerDesktopDiscord botnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:UsersEric MüllerDesktopDiscord botnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:301:10)
at WebSocket.onMessage (C:UsersEric MüllerDesktopDiscord botnode_moduleswslibevent-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:UsersEric MüllerDesktopDiscord botnode_moduleswslibwebsocket.js:825:20)

这是我的代码:

const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
const fs = require('fs');
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('Codelyon 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 === 'ping'){
client.commands.get('ping').execute(message, args);
}
});
client.login('   '); (DISCLAMER! THE TOKEN IS FILLED IN AND CORRECT)

ping.js:

module.exports = {
name: 'ping',
description: "this is a ping command!",
execute(message, args){
message.channel.send('pong!');
}
}

正如错误提示的那样,您的代码中很可能有一个错别字:

ReferenceError:clicent未在客户端定义。(C:UsersEric mllerDesktopDiscord botMain.js:27:9)

该错误告诉您,在Main.js文件的第27行开头,您有client,但它可能应该是client。

最新更新