Which code says the number of voice channels on the server? [duplicate] - discord.js

This question already has an answer here:
How to get the number of voice channels in a guild?
(1 answer)
Closed 2 years ago.
I'm trying to create a serverinfo command, but first I need to know which code says the number of voice channels on the server

To get the number of voice channels in a guild, you could do:
const voiceChannelCount = message.guild.channels.filter(c => c.type === 'voice').size;
which will filter through all the channels, only get the voice channels, and get its size.
Note: I noticed you're a new member! First of all, welcome to StackOverflow. Second of all, be sure to mark the answer of your questions by clicking the check next to the answer that helped you solve it so people know this question got it's answer and someone new can also find it easily!

You need to first get all the channels in the guild, then filter out the ones that are not voice channels.
// let's say guild is the guild you're working with, and that it's already cached
guild
.channels // Guild.channels
.cache // GuildChannelManager.cache
.filter(channel => channel.type == 'voice') // Collection.filter()
.size // Map.size

Related

Discord.js channel is undifined when getting it with ID [duplicate]

This question already has an answer here:
Discord displays #deleted-role while the role is still avalible
(1 answer)
Closed 1 year ago.
const other_channel_id = 913189654247907380;
const other_channel = interaction.guild.channels.cache.get(other_channel_id.toString());
For some reason the other_channel is undifined.
I try to use it in a InteractionCreate event, if there is something special about that.
The channel is a voice channel
JavaScript does not handle big numbers that well, which is why even with .toString(), it didn't turn into what you wanted. Change the Number into a String directly and it should work
const other_channel_id = "913189654247907380";
const other_channel = interaction.guild.channels.cache.get(other_channel_id)
Take a look at what JavaScript turns the ID into (more specifically the ending digits):
console.log(913189654247907380)
console.log("String version: " + (913189654247907380).toString())

How do I check if a message was sent in a specific channel via. channel ID discord.py?

So I'm coding a Discord bot for a friend and I need to see if a message was sent in a specific channel.
I tried a few things, asked a few people, and searched for an answer, but I couldn't find any.
This is about the closest I've gotten and I've tried changing a few objects:
if message.channelID == ('#858884357271322634'):
await message.channel.send ('I checked and verified the channel.')
Your check does not really makes sense, there is no such message.channelID.
Simply compare message.channel.id with the ID you want to and insert it correctly.
Simple example:
if message.channel.id == 858884357271322634:
await message.channel.send("I checked and verified the channel.")

Is there a way I can join a discord server, through its ID, My bot is already in the server [duplicate]

This question already has an answer here:
Creating an invite and send it to an user that is not in your server/guild
(1 answer)
Closed 2 years ago.
My bot is in some servers that I'm not in, and I want to join those servers with the help of my bot.
I tried a lot of different code, but none of them seemed to work for me. I found a question that was similar to mine but it was for discord.py (python).
My bot is coded in Discord.JS.
h
I want to able to do +create (ID) and then it returns with that servers invite link.
ex: +create 2320329132 | Return: discord.gg/Ud9283
sorry my english isnt good. thank you if you can help me :)
let guild = client.guilds.cache.get(args[0]);
let channel = guild.channels.cache.filter(ch => ch.type === "text");
channel.first().createInvite({ maxUsers: 1, maxAge: 0, unique: true})
.then(invite => message.channel.send(`https://discord.gg/${invite.code}`));
I am assuming that you defined args and client already. guild stores the server you provided by its ID. channel filters every text channel and stores it. Then we take the first found text channel by using channel.first() and create an invite by using .createInvite() (because you only can create an invite to a channel). After that we use .then to get the invite code and send the full link to the current text channel.

Why is my discord bot only finding 3 members in my server when there are over twenty? [duplicate]

This question already has an answer here:
None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?
(1 answer)
Closed 2 years ago.
I'm trying to have my bot select a random member for this raffle, but it is only coming up with the same 3 members. Me, itself, and a music bot.
All I'm doing is this
let randommember = message.guild.members.cache.random()
console.log(winner)
But no matter what I do it comes up with those 3 members. I tried having it shuffle people with a specific role, but unless one of those 3 members has the role, it comes up with an error.
let RaffleContenstant = message.guild.roles.cache.get("771443215936520252")
let winner = RaffleContestant.members.random()
Discord recently rolled out Priveliged Gateway Intents, which are mostly to do with server members and presence.
By default, those intents are turned off, so if you want to access guild member and presence-related data, you should probably change your gateway intents at the Discord Developer Portal.

Discord.js - Get Another Channel's Topic

I'm trying to basically do what the title says.
I've tried
let channel = message.channel.get(68352726916713XXXX)
message.channel.send(channel.topic)
and stuff like that, But nothing works.
Any suggestions or answers?
If you are trying to get a channel in the same guild as the message was sent in, use message.guild.channels.get. Otherwise, use client.channels.get.
let channel = message.guild.channels.get("68352726916713XXXX");
message.channel.send(channel.topic);

Resources