I am new to programming a Discord bot (and I love it), and it has problems responding. When I start it with node main.js
, it works as normal until I do something like -ping
, upon which it stops working.
Here is the error that I receive:
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 bot
ode_modulesdiscord.jssrcclientactionsMessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:UsersEric MüllerDesktopDiscord bot
ode_modulesdiscord.jssrcclientwebsockethandlersMESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:UsersEric MüllerDesktopDiscord bot
ode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:UsersEric MüllerDesktopDiscord bot
ode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:UsersEric MüllerDesktopDiscord bot
ode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:301:10)
at WebSocket.onMessage (C:UsersEric MüllerDesktopDiscord bot
ode_moduleswslibevent-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:UsersEric MüllerDesktopDiscord bot
ode_moduleswslibwebsocket.js:825:20)
Here is my code:
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!');
}
}
question from:
https://stackoverflow.com/questions/65909024/discord-bot-will-not-respond-shuts-down 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…