Skip to content

How to fix cannot read property “send” of undefined

This question might have a few duplicates, but the code there is different and none of the answers work for me. I’m new to discord.js so it might just be a silly mistake.

This is my code –

var Discord = require('');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.add(new logger.transports.Console, {
    colorize: true
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
bot.on('ready', function (evt) {'Connected');'Logged in as: '); + ' - (' + + ')');
client.on('message', function(message) {
    if (message.startsWith('^')) { //condition is false, even though message starts with ^
        if (message.startsWith('^ping')) {
            message.mentions.users.forEach((k, v) => {
      'Hello,' + v + '!');
        } else if (message.startsWith('^dice')) {
  'You rolled a a' + Math.floor((Math.random() * 100) + 1) + "!");
        } else {
  "Command not found.");
    } else {"debug") //error in this line

I really don’t know how to fix this, so all the solutions I have tried lead to this error. Also if you see any other fixes to this code please point it out. Here is the error:"debug")

TypeError: Cannot read property 'send' of undefined
    at DiscordClient.<anonymous> (C:UsersuserDocumentsUltraBotbot.js:32:25)
    at DiscordClient.emit (events.js:315:20)
    at DiscordClient.handleWSMessage (C:UsersuserDocumentsUltraBotnode_modulesdiscord.iolibindex.js:1854:11)
    at WebSocket.emit (events.js:315:20)
    at Receiver.ontext (C:UsersuserDocumentsUltraBotnode_moduleswslibWebSocket.js:841:10)
    at C:UsersuserDocumentsUltraBotnode_moduleswslibReceiver.js:536:18
    at Receiver.applyExtensions (C:UsersuserDocumentsUltraBotnode_moduleswslibReceiver.js:371:5)
    at C:UsersuserDocumentsUltraBotnode_moduleswslibReceiver.js:508:14
    at Receiver.flush (C:UsersuserDocumentsUltraBotnode_moduleswslibReceiver.js:347:3)
    at Receiver.finish (C:UsersuserDocumentsUltraBotnode_moduleswslibReceiver.js:541:12)



The problem is that you are using code for Discord.js, while using the package. The ways that you send and receive messages is vastly different. I suggest that you switch to discord.js, as that is what you are writing the code to work for.

User contributions licensed under: CC BY-SA
10 People found this is helpful