Search code examples
javascriptdiscord.js

Creating discord bot js - Collections is not defined


I am new to coding a discord bot with JS and I am not sure why I am getting an error when I am trying to make a collection for a library of other .js files. I am instead greeted with the image below:enter image description here

Broken code: https://sourceb.in/x2EFkdb5sV

Line 14.

I tried defining Collections using another question on this site with similar problems:"Collection is not defined" when trying to create a discord bot .

It wasnt the answer I was looking for as it deviates from making a collection.


Solution

  • You must require the class Collection from discord.js to be able to use the Collection class.

    At the beggining of your code, change const { Client, GatewayIntentBits } = require('discord.js'); to const { Client, GatewayIntentBits, Collection } = require('discord.js');

    In addition, its Collection, not Collections (there is no s). So you will have to write new Collection(); instead of new Collections();.