Discord.js - bot.guilds.get is not a function? - discord.js

I made a discord bot in discord.js about a year ago and wanted to do some new things with it today, so I went back to it. It worked fine before for a long time, but now on the line server = bot.guilds.get(serverID); is gives me the error 'bot.guilds.get is not a function' when it should be. What am I doing wrong?

I'm assuming you're getting the error because you're using Discord.js V12 and your bot was made for Discord.js V11.
The solution to this problem is to use:
bot.guilds.cache.get("GuildID")
instead of:
bot.guilds.get("GuildID")
https://discord.js.org/#/docs/main/stable/class/GuildManager?scrollTo=cache

Related

How do I create a stickied message in Discord.js

I've looked all over and I can't find a solution.
I'm using discord js using non-slash commands.
How could I make it so you have a message from the bot and if someone types in the channel the bot's message will get deleted and resent
I want to do this in a sense of a server request channel so you need to add the channel you want the command to run and what you want it to say:
e.g:
Stickied Message
Name:
Request Needed:
Approved By:
how could I program that? Thanks :) <3
I ahve googled online and can't see anything relating to this topic - maybe I'm not searching the right things?
Tried Discord.js V13 | Sticky Message but did not work

Does discord limit what information can you get using a bot?

I wrote a quick discord bot as a joke, that just sends a gag message to my friend every 3 or 4 days. However, I could not find my friend's account using client.users.cache.get() or client.users.fetch(). I made sure the ID I put in was correct, to no avail. I then tested it with my own account, which worked perfectly fine. The only difference was that I was in a server with this tester bot, and everyone else in that bot-dev server could receive messages from this bot. I also realized it is impossible to get other information, (friends, etc.). Is this intentional, or is this simply a bug?

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)

How to delete all channels In a discord server(js)

I am attempting to delete channels on my discord server using my bot and this is the code:
if (message.content === 'tanbu')
message.guild.channels.forEach(channel => channel.delete())
.then(console.log)
.catch(console.error);
the error is :
TypeError: message.guild.channels.forEach is not a function
What do I do?
This would've worked in Discord JS V11, but not in V12.
This is what you're looking for:
message.guild.channels.cache.forEach(channel => channel.delete());
https://discord.js.org/#/docs/main/stable/class/GuildChannelManager?scrollTo=cache
Maybe you should think twice before doing such actions. Because this leads to violation of the Discord tos. And it even spams the discord api. which could lead you to a api ban to a particular endpoint or globally sometimes. Even if the library has ability to slow down it , you could still easily bypass it. The ideal solution here is using a sleep function , and not using a forEach loop, maybe a for loop would do better.
Still this is not recommended doing , if your intention is to nuke servers.
I believe that that is for raiding and self bots witch is against discord TOS
i defiently would think w

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