Manuelmaccou
Manuelmaccou

Reputation: 1

TypeError when trying to create a discord bot

I'm trying to build a discord bot that sends data to an airtable. This one sends user info when they join my server. I have the following code, but every time I try to run it, I get the following error:

TypeError: Cannot read properties of undefined (reading 'GUILDS')at Object.

This is the code:

const { Intents } = require('discord.js');
const Discord = require('discord.js');
const Airtable = require('airtable');

const client = new Discord.Client({ 
    token: 'TOKEN_ID',
    intents: [Intents.GUILDS, Intents.GUILD_MEMBERS]
});

Airtable.configure({ apiKey: 'API_KEY' });
const base = Airtable.base('BASE_ID');

client.on('guildMemberAdd', member => {
  base('New Members').create({
    'Username': member.user.username,
    'Time Joined': new Date().toISOString()
  }, function(err, record) {
    if (err) {
      console.error(err);
      return;
    }
    console.log(`Added new record with ID ${record.getId()}`);
  });
});

client.login();

Upvotes: 0

Views: 64

Answers (1)

Bycop
Bycop

Reputation: 51

Using Discord.js v14, the way to declare intents is as follows:

import { Client, GatewayIntentBits } from "discord.js";

const client = new Client({
    intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers
  ]
});

and your token should be put in client.login

client.login("your-bot-token");

Upvotes: 1

Related Questions