Enable intents for discord.py bot - discord

Im making a discord bot, and every time it joins a new server, the bot sends me the server info and an invite. However, when I've tested this, it always shows one member which is itself. I have both presence and members intents enabled in the discord developer portal, but it still isn't working.
I then changed some code to Guild.fetch_members() to which I received the error:
discord.ext.commands.errors.CommandInvokeError:
Command raised an exception:
ClientException:
Intents.members must be enabled to use this.
As I said before, on the discord developers website member intents are enabled and I have had this code before without this issue.
When I had this code working before, it was using 1.5.x (I cant remember exactly) and now its using 1.6.0, so something in the new update may prevent this from working, but this is unusual to me, so how can I resolve this issue?

intents were introduced in 1.5.0 so I don't think they were working before, but answering your question
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(..., intents=intents)
Also remember to enable privileged member intents in the developer portal
How to enable privigeled intents

Related

Why does the Discord JavaScript library gives me this error?

So i'm getting an error like this.
`
Error [DISALLOWED_INTENTS]: Privileged intent provided is not enabled or whitelisted.
at WebSocketManager.createShards (/home/runner/Discord-500-Commands-Bot-1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:245:15)
at async Client.login (/home/runner/Discord-500-Commands-Bot-1/node_modules/discord.js/src/client/Client.js:254:7)
[15:16]
`
Can you help?
Windows 20
I tried to upgrade from version 9 to version 15 but it wouldnt work
The error explains it all!
Head over to Discord Developer Portal and select your application.
Click on Bot and scroll down to Privileged Gateway Intents
Enable the required ones and you're good to go!
Read more about these intents here

Not managing to transfer my code onto a different bot

So I have my bot which I now transferred onto a Heroku server, with this I made a new bot which I named ex Test Bot, but for some reason when I went into my config.json with the code
{
"token": "DISCORD BOT ID THING"
}
Now when I change the following to my test bots ID which I will run from my PC, it gives me this wierd error
I really have no clue searched online couldnt fined anthing, I hope one of you guys could help. Thanks!
You're probably using an intent that you don't have permission to use or isn't enabled.
You'll have to go to Discord Developer Portal, choose your application, go to the Bot section, and enable all the intents. (Or the ones you are using.)
Note that once your bot reaches 100 or more servers, this will require verification and whitelisting.
Bot Verification and Data Whitelisting

How to trigger a block of code when a user joins a guild

I've made a bot with discord.js and I want to run some code when a user joins my guild. The obvious answer here is the client event guildMemberAdd, which worked until about a month ago. For some odd reason it stopped working and I've been trying to fix it, but I have no idea what the problem is.
Here is a super simplified version of my script since it's over 3000 lines long:
client.on('guildMemberAdd', member => {
console.log(`${member.user.tag} joined`);
});
I've even tried a try and catch block but everything seems fine. What am I doing wrong here?
They changed it so you have to go on the developer portal, click on your bot en turn Privileged Gateway Intents on then it should work again (it is in the bot tab)

Discord.js - Bot messages LIMIT?

I have a bot with which you have to verify yourself to be on our Discord server
(The verification takes place in the DM`s)
Recently we have the problem that certain members of our Discord cannot write to the bot.
Everyone allowed everyone to send a message to the person
Each of the people is on our Discord Server, allows the person to write messages and have not blocked the bot
The bot does not issue any error messages
We would be delighted to find a quick solution
Since you haven't provided any code snippets, logs or error messages, it's a bit difficult to assess your situation... but here are some basic troubleshooting steps that you could follow:
Remove and re-authenticate the bot into the server.
Double check that you have enabled DM's.
Check the console for any errors that could pertain to direct messaging issues with users in the server. (especially from successful DM's)
Try to notice any differences between the users in the server who are
able to message the bot, versus those who cannot.
Ensure the bot isn't running more than one instance. (i.e. you might
have more than one bot running on the same token!)
I highly recommend giving more detail, because usually a question pertaining to broken/lost functionality would usually attach code or error logs to help diagnose the issue.
Okay, the problem is that you either didn't enable DMs or the bot is not in the server.
Otherwise, this problem will not occur.

Getting number of members and servers a bot is serving

So I went through the discord.js guide, and found that client.guilds.size and client.users.size is for finding no of users and servers a bot is on. But when I implement it I get "undefined". Any reason why?
Try client.guilds.cache.size and client.users.cache.size.
This changed in discord.js v12.
client.users has been changed from a Collection to a Manager.
client.guilds has been changed from a Collection to a Manager.

Resources