Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
ReferenceError: client is not defined | client.userSettings = new Collection();

i have coded a discord bot but i have a problem, when i start the bot i have this problem : "ReferenceError: client is not defined", i have downloaded requirements ect...

The client :

client.userSettings = new Collection();

My interactionCreate.js :

// Check the guide at the beginning if you don't understand paths.
const User = require("../Models/User");
const cmd = client.Commands.get(interaction.commandName);
if (cmd) {
  let user = client.userSettings.get(interaction.user.id);
  // If there is no user, create it in the Database as "newUser"
  if (!user) {
    const findUser = await User.findOne({ Id: interaction.user.id });
    if (!findUser) {
      const newUser = await User.create({ Id: interaction.user.id });
      client.userSettings.set(interaction.user.id, newUser);
      user = newUser;
    } else;
  }

  if (cmd.premium && user && !user.isPremium) {
    interaction.followUp(`You are not premium user`);
  } else {
    cmd.run({ client, interaction, args });
  }
}

My User.js :

const mongoose = require("mongoose");

// The heart of the User, here is everything saved that the User does.
// Such as Levels, Courses, Premium, Enrolled, XP, Leaderboard.
const user = mongoose.Schema({
  Id: {
    type: mongoose.SchemaTypes.String,
    required: true,
    unique: true,
  },
  isPremium: {
    type: mongoose.SchemaTypes.Boolean,
    default: false,
  },
  premium: {
    redeemedBy: {
      type: mongoose.SchemaTypes.Array,
      default: null,
    },

    redeemedAt: {
      type: mongoose.SchemaTypes.Number,
      default: null,
    },

    expiresAt: {
      type: mongoose.SchemaTypes.Number,
      default: null,
    },

    plan: {
      type: mongoose.SchemaTypes.String,
      default: null,
    },
  },
});
module.exports = mongoose.model("user", user);

Please help me i very need help pls, thanks you.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Just utilize the client that you've passed to your commad:

  if (cmd.premium && user && !user.isPremium) {
    interaction.followUp(`You are not premium user`);
  } else {
    cmd.run({ **client**, interaction, args });
  }
}

Also it'd be good to see how your command looks.

about 4 years ago · Juan Pablo Isaza Report

0

The issue is you do not have your client defined in your interactionCreate.js. To define it, use const client = <something> if you need help with client, read this documentation.

If you are new to DiscordJS V13, you can view the docs here

Other steps you can do to trouble shoot is to reinstall discordjs and verify that you are using node version 16 and higher.

Node: In your terminal put node -v

Discord Js Reinstall: In your terminal put npm uninstall discord.js then npm install discord.js or npm install discord.js@13.6.0

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!