Reputation: 53
I am making a chatbot but I keep getting this error:
TypeError: client.on is not a function
The event code:
const { chatBot } = require('reconlx');
const client = require('../app');
const Schema = require('../database/models/chatbot-channel');
client.on("message", async (message) =>{
if(!message.guild || message.author.bot) return;
Schema.findOne({ Guild: message.guild.id }, async(err, data) => {
if(!data) return;
if(message.channel.id !== data.Channel) return;
chatBot(message, message.content, message.author.id);
});
});
The model I am using:
const { Schema, model } = require('mongoose');
model.models = model(
"chatbot",
new Schema({
Guild: String,
Channel: String,
})
);
The set channel command:
const mongoose = require('mongoose');
const { Client, Message, MessageEmbed } = require('discord.js');
const Schema = require('../database/models/chatbot-channel');
module.exports = {
name: 'set-chatbot',
description: 'sets a channel for a chatbot!',
devOnly: true,
async execute(message, args, client) {
const channel = message.mentions.channels.first() || message.channel;
Schema.findOne({ Guild: message.guild.id }, async(err, data) => {
if(data) data.delete();
new Schema({
Guild: message.guild.id,
Channel: channel.id,
}).save();
message.channel.send(`Saved Chatbot Channel To ${channel}`);
});
},
};
Does anyone know what I did wrong? I don't see the mistake.
Upvotes: 0
Views: 7712
Reputation: 1880
You're not creating the client
correctly. You need to add this at the very top of your event code
:
const Discord = require('discord.js');
const client = new Discord.Client();
Upvotes: 1