xolagix
xolagix

Reputation: 3

How to fix "UnhandledPromiseRejectionWarning: ReferenceError: content is not defined"

I'm working on the bot. I used ping template from example bot yet it when I use the command it does not work.

(node:5696) UnhandledPromiseRejectionWarning: ReferenceError: content is not defined
    at Client.<anonymous> (D:\bipbot\index.js:18:5)
    at Client.emit (events.js:210:5)
    at MessageCreateHandler.handle (D:\bipbot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (D:\bipbot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (D:\bipbot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (D:\bipbot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (D:\bipbot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:210:5)
    at Receiver.receiverOnMessage (D:\bipbot\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:210:5)

This what I get when I use the ping command.

import { Client } from "discord.js";
const client = new Client();
import { prefix, token } from "./config.json";

client.on('ready', () => {
  console.log(`Запущено. Используется в качестве пользователя ${client.user.tag}!`);
  client.user.setActivity(`Используется префикс ${prefix}.`)
});

client.on("guildCreate", guild => {
    //Логи присоединения к серверу
    console.log(`Присоединлся к серверу ${guild.name}. ID сервера - ${guild.id}. `)
});

client.on("message", async message => {
    if(content.author.bot) return;
    if(message.content.indexOf(prefix) !== 0) return;


    const args = message.content.slice(prefix.length).trim().split(/+/g);
    const command = args.shift().toLowerCase();

    //Команды. Не дай Монолит ты их начнешь писать выше.

    if(command === 'ping')  {
        const m = await message.channel.send(`Пинг? :thinking:`);
        m.edit(`Понг! Задержка равна ${m.createdTimestamp - message.createdTimestamp}мс. Задержка API равна ${Math.round(client.ping)}мс.`);
    };

Is the part that seems broken.

Upvotes: 0

Views: 1225

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 85151

if(content.author.bot) return;

As the error says, content is not defined. You probably meant to do:

if(message.author.bot) return;

Upvotes: 2

Related Questions