#Following a tutorial from 2020 and unsure of how I'm supposed to define Intents.

29 messages · Page 1 of 1 (latest)

quiet goblet
#

I'm following this tutorial by Sethey17 to make a simple Discord bot for my server that would be able to bulk delete messages in response to a command.
https://www.youtube.com/watch?v=fx6oJ4PQDOs

I'm on step two and I keep getting the following error when I try to run the code in the terminal. I've checked the code for typos and used JSHint.

From what I can understand and find online (mind you, this is the first time I've ever made a bot or used Javascript) this is because Discord needs me to set the permissions for the bot via Intents. I can't seem to get a confirmation on exactly how to do this anywhere online, other than that the way used in Sethey17's tutorial may no longer be correct. How do I fix this so I can move on to the next step?

`Node.js v22.11.0
PS C:\Users\dogkn\Documents\Tomatogen> node index.js
C:\Users\dogkn\Documents\Tomatogen\node_modules\discord.js\src\client\Client.js:529
throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
^

TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\dogkn\Documents\Tomatogen\node_modules\discord.js\src\client\Client.js:529:13)
at new Client (C:\Users\dogkn\Documents\Tomatogen\node_modules\discord.js\src\client\Client.js:80:10)
at Object.<anonymous> (C:\Users\dogkn\Documents\Tomatogen\index.js:2:13)
at Module._compile (node:internal/modules/cjs/loader:1546:14)
at Object..js (node:internal/modules/cjs/loader:1689:10)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5) {
code: 'ClientMissingIntents'
}
`

We are no longer helping with bot coding. I am currently in college and no longer have time to help or make videos, and my helpers have lives too so they arent available much either. If you are really interested in making discord bots I suggest you go watch some JavaScript tutorials and read the discord.js documentation. Thank you for all the su...

▶ Play video
fathom harnessBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
wheat snow
#

the only tutorial you should be following is the official guide

valid rivetBOT
wheat snow
#

that tutorial seems to be using djs v11

#

that's 3 major versions behind

#

(we're on v14)

#

From what I can understand and find online (mind you, this is the first time I've ever made a bot or used Javascript) this is because Discord needs me to set the permissions for the bot via Intents
intents aren't really permissions, but like a way to tell discord what data the bot needs, so you don't get computationally burdened with events you don't care about

#

the only intents that work kind of like "permissions" are the priviliged ones, like MESSAGE_CONTENT, they're related to user privacy and need to be approved manually by discord when you verify

quiet goblet
trim sedge
#

you should not do that. its api spam

wheat snow
#

well the guide won't tell you everything, but you should use it as the starting point

quiet goblet
# trim sedge you should not do that. its api spam

I will explain my problem and perhaps you can explain to me a way to do this correctly, because I'm confused as to how this is spam.

I have a Discord server with a channel for people to post when they go live. The channel is locked and streamers can only post there, once, when they go live. I would like to be able to clear this channel from time to time, because once the streamer is no longer live these messages are useless. I want to make a bot where when a moderator types a specific command in the channel, it clears the channel of all of these messages (once again, it would be nice if it was before a certain period of time, so the moderator can choose not to delete messages that are still relevant) instead of the moderator having to go in and manually delete them one by one.

trim sedge
#

you can only bulk delete 100 messages from up to the past 14 days

#

you can just use a thread for that and delete it after

quiet goblet
trim sedge
#

deleting 100 messages at a time will result in api spam

quiet goblet
# trim sedge deleting 100 messages at a time will result in api spam

ClearChat offers the option to clear messages from a channel and is approved by Discord, so I assume there is a legitimate way to give your bot orders to delete messages. I wanted something functionally similar. I assume I would have to add some limitations to prevent people from spamming the bot. For the purposes of the bot I'm making, 100 messages would be a week or two, minimum, more like a month.

wheat snow
#

that bot can't delete more than 100 messages

quiet goblet
wheat snow
#

its clearall command clones the channel, its clear command uses the GuildMessageManager#fetch() method, which uses the channelMessages endpoint, which doesn't support more than 100 messages

#

it doesn't seem to perform any kind of iteration

#

unless its public version is different than the one in their github

quiet goblet
wheat snow
#

you can use the bulkDelete method then

valid rivetBOT
#

method TextChannel#bulkDelete() @14.16.3
Bulk deletes given messages that are newer than two weeks.


// Bulk delete messages
channel.bulkDelete(5)
  .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
  .catch(console.error);

wheat snow
#

that bot only seems to fetch first to support filtering

#

though bulkDelete will fetch first if you only specify a number anyways

#

use whichever fits your needs