2
2
const path = require ( 'path' )
3
3
const fs = require ( 'fs' )
4
4
// Only import the Client class from Discord.js
5
- const { Client } = require ( 'discord.js' )
5
+ const { Client, Intents } = require ( 'discord.js' )
6
6
7
7
require ( 'dotenv' ) . config ( )
8
8
@@ -34,8 +34,13 @@ const config = (() => {
34
34
35
35
// Store the commands in a Map (slightly better than a raw object)
36
36
const commands = new Map ( )
37
+ // Define gateway intents
38
+ const intents = new Intents ( [
39
+ Intents . NON_PRIVILEGED , // include all non-privileged intents, would be better to specify which ones you actually need
40
+ "GUILD_MEMBERS" , // lets you request guild members
41
+ ] ) ;
37
42
// Create the client
38
- const bot = new Client ( { disableEveryone : true } )
43
+ const bot = new Client ( { partials : [ 'MESSAGE' , 'CHANNEL' , 'REACTION' ] , ws : { intents } , fetchAllMembers : true , disableEveryone : true } )
39
44
40
45
// Store the config and commands on the bot variable so as to make them
41
46
// easily accessible in commands and other files
@@ -67,7 +72,7 @@ fs.readdirSync(path.resolve(__dirname, 'commands'))
67
72
68
73
bot . on ( 'ready' , ( ) => {
69
74
console . log ( `Logged in as ${ bot . user . tag } (ID: ${ bot . user . id } )` )
70
- bot . generateInvite ( [
75
+ bot . generateInvite ( { permissions : [
71
76
'SEND_MESSAGES' ,
72
77
'MANAGE_MESSAGES' ,
73
78
// Here are some other common permissions you might want to include:
@@ -88,7 +93,7 @@ bot.on('ready', () => {
88
93
// 'MOVE_MEMBERS',
89
94
// 'MUTE_MEMBERS',
90
95
// 'DEAFEN_MEMBERS',
91
- ] ) . then ( invite => {
96
+ ] } ) . then ( invite => {
92
97
// After generating the invite, log it to the console
93
98
console . log ( `Click here to invite the bot to your guild:\n${ invite } ` )
94
99
} )
0 commit comments