Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

error handling - Discord bot will not respond, shuts down

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As the error suggests, you most likely have a typo somewhere in your code:

ReferenceError: clicent is not defined at Client. (C:UsersEric MüllerDesktopDiscord botMain.js:27:9)

The error tells you that at the beginning of line 27 in Main.js file, you have clicent, but it was probably supposed to be client.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...