Discord bot command not working returning error

So I'm trying to start learning how to code a Discord bot. But when I run the code and say the command "!hello" it just says this error message:

Uncaught ReferenceError: hello is not defined No debugger available, can not send 'variables' Process exited with code 1

How do I fix it?

const { Client, MessageAttachment } = require("discord.js");
const bot = new Client();

const token = new String("")

bot.on('ready', () =>{
    console.log("I am online!");
})

bot.on('message', (message) =>{

    console.log("HELLO");
    
    if(message.author.bot) return;
    let prefix = '!';
    let MessageArray = message.content.split(' ');

    let cmd = MessageArray[0].slice(prefix.length);
    let args = MessageArray.slice(1);

    if(!message.content.startsWith(prefix)) return;

    //command

    if(cmd === hello){
        console.log("command sent");
        message.channel.send("Hello there!");
    }
})

bot.login(token censored)

Upvotes: 0

Views: 185

Answers (1)

Billy Robinson
Billy Robinson

Reputation: 36

Within your code, you have

if(cmd === hello){

However, hello is not a variable that you have defined in your code, hence the error stating that you don't have it defined, instead, it should be placed into quotation marks to express that it should compare cmd to "hello" (a string).

For example:

if(cmd === "hello"){

Upvotes: 2

Related Questions