Skip to content

Commit 8c9b709

Browse files
MadzahttrEthan Matten
and
Ethan Matten
authored
Add gateway intents and fix generateInvite deprecation warning (#3)
Co-authored-by: Ethan Matten <ethanm@nanonet.co.nz>
1 parent d77d90b commit 8c9b709

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Put your bot's Discord token here -- get it at https://discord.com/developers/applications
1+
# Put your bot's Discord token here -- get it at https://discord.com/developers/applications and make sure to enable the server membr intent
22
BOT_TOKEN=
33
BOT_PREFIX=$

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"author": "Rayzr522 <rayzr522@gmail.com>",
88
"license": "MIT",
99
"dependencies": {
10-
"discord.js": "^12.3.1",
10+
"discord.js": "^12.5.1",
1111
"dotenv": "^8.2.0"
1212
},
1313
"scripts": {

src/bot.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const path = require('path')
33
const fs = require('fs')
44
// Only import the Client class from Discord.js
5-
const { Client } = require('discord.js')
5+
const { Client, Intents } = require('discord.js')
66

77
require('dotenv').config()
88

@@ -34,8 +34,13 @@ const config = (() => {
3434

3535
// Store the commands in a Map (slightly better than a raw object)
3636
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+
]);
3742
// 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 })
3944

4045
// Store the config and commands on the bot variable so as to make them
4146
// easily accessible in commands and other files
@@ -67,7 +72,7 @@ fs.readdirSync(path.resolve(__dirname, 'commands'))
6772

6873
bot.on('ready', () => {
6974
console.log(`Logged in as ${bot.user.tag} (ID: ${bot.user.id})`)
70-
bot.generateInvite([
75+
bot.generateInvite({ permissions: [
7176
'SEND_MESSAGES',
7277
'MANAGE_MESSAGES',
7378
// Here are some other common permissions you might want to include:
@@ -88,7 +93,7 @@ bot.on('ready', () => {
8893
// 'MOVE_MEMBERS',
8994
// 'MUTE_MEMBERS',
9095
// 'DEAFEN_MEMBERS',
91-
]).then(invite => {
96+
]}).then(invite => {
9297
// After generating the invite, log it to the console
9398
console.log(`Click here to invite the bot to your guild:\n${invite}`)
9499
})

0 commit comments

Comments
 (0)