Iced Queen
Iced Queen
DIAdiscord.js - Imagine an app
Created by Iced Queen on 11/2/2024 in #djs-questions
Stats command returning wrong member count after X hours
const promises = [
client.shard.broadcastEval(c => c.guilds.cache.size)
.catch(error => {
console.error(new Date(), `Error in guild count for shard:`, error);
return 0;
}),
client.shard.broadcastEval(c => c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0))
.catch(error => {
console.error(new Date(), `Error in member count for shard:`, error);
return 0;
}),
client.shard.broadcastEval(c => c.ws.status === 0 ? true : false)
.catch(error => {
console.error(new Date(), `Error in shard connection status:`, error);
return false;
})
];

let totalGuilds;
let totalMembers;
let responsiveShards;
await Promise.all(promises.map(promise =>
Promise.resolve(promise)
))
.then(results => {
totalGuilds = results[0].reduce((acc, guildCount) => acc + guildCount, 0);
totalMembers = results[1].reduce((acc, memberCount) => acc + memberCount, 0);
responsiveShards = results[2].filter(responsive => responsive).length;
})
.catch(error => {
console.error(new Date(), `Error fetching shard data:`, error);
});
const promises = [
client.shard.broadcastEval(c => c.guilds.cache.size)
.catch(error => {
console.error(new Date(), `Error in guild count for shard:`, error);
return 0;
}),
client.shard.broadcastEval(c => c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0))
.catch(error => {
console.error(new Date(), `Error in member count for shard:`, error);
return 0;
}),
client.shard.broadcastEval(c => c.ws.status === 0 ? true : false)
.catch(error => {
console.error(new Date(), `Error in shard connection status:`, error);
return false;
})
];

let totalGuilds;
let totalMembers;
let responsiveShards;
await Promise.all(promises.map(promise =>
Promise.resolve(promise)
))
.then(results => {
totalGuilds = results[0].reduce((acc, guildCount) => acc + guildCount, 0);
totalMembers = results[1].reduce((acc, memberCount) => acc + memberCount, 0);
responsiveShards = results[2].filter(responsive => responsive).length;
})
.catch(error => {
console.error(new Date(), `Error fetching shard data:`, error);
});
For the first hours, sometimes even a day it returns the correct member count, but sometimes randomly it starts returning the wrong member count. Then if I restart the bot, it shows the correct count again. Before restart: Server Count: 34,726 Member Count: 21,783 After restart: Server Count: 34,697 Member Count: 1,367,868 It has even said "Member Count: 0" before.
41 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 5/3/2023 in #djs-questions
Slash command option 'autocomplete'
Hey there, So I don't really understand what the .setAutocomplete(true/false) does when creating options on commands. Can someone explain it to me? 🙂
3 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 4/29/2023 in #djs-questions
Can you tell if a User was added or removed in a User Select Menus?
In a userSelectMenu is there a way to tell if a user was added or removed from the selected users
4 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 4/18/2023 in #djs-questions
TypeError [InvalidType]: Supplied parameter is not a User nor a Role.
17 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 4/12/2023 in #djs-questions
Ready event randomly stopped working
Does Discord have issues? Until a few hours ago my bot worked completely fine and have been for several months, but now it suddenly stopped triggering ready events?
10 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 3/15/2023 in #djs-questions
Discord or D.js bug?
Is it a Discord bug or Discord.js bug that Age-gated commands are still hidden in Forum posts / Threads even if the Forum channel / Channel where the Thread is created is NSFW marked?
4 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 3/12/2023 in #djs-questions
Do I have to run "npm install" with all the "@"s?
Like do I need to run both npm install discord.js@latest and npm instal @discordjs/[email protected] etc...?
9 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 3/9/2023 in #djs-questions
How can I prevent the Error [ShardingInProcess]: Shards are still being spawned.
Error [ShardingInProcess]: Shards are still being spawned. How can I prevent this error from being logged? while (!client.isReady()) return; is the first thing I have in my interactionCreate event btw.
14 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 2/11/2023 in #djs-questions
allowedMentions
const client = new Client({
intents:
[
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates
],
allowedMentions: {
parse:
[
"users",
"roles"
]
},
});
const client = new Client({
intents:
[
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates
],
allowedMentions: {
parse:
[
"users",
"roles"
]
},
});
I got this in my client options, but it doesn't it give notifications, neither is the message highlighted? What am I doing wrong?
45 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 12/29/2022 in #djs-questions
Issue with sharding after 4 shards
const array = await client.shard.broadcastEval(async (c, { userId, apprentice, adept, expert, master, legendary, patron }) => {
let donor = '\❌'
let membership = 'None'
const server = c.guilds.cache.get('992937347094155356')
if (server) {
let member;
try {
member = await server.members.fetch(`${userId}`)
} catch (error) {
member = undefined
}
if (
member !== undefined &&
(
member.roles.cache.has(apprentice) ||
member.roles.cache.has(adept) ||
member.roles.cache.has(expert) ||
member.roles.cache.has(master) ||
member.roles.cache.has(legendary)
)
) {
donor = '\✅'
if (member.roles.cache.has(apprentice)) {
membership = 'Apprentice'
}
if (member.roles.cache.has(adept)) {
membership = 'Adept'
}
if (member.roles.cache.has(expert)) {
membership = 'Expert'
}
if (member.roles.cache.has(master)) {
membership = 'Master'
}
if (member.roles.cache.has(legendary)) {
membership = 'Legendary'
}
}
await server.members.fetch()
return { donor, membership };
}
return { donor, membership };
}, {
context: {
userId: interaction.user.id,
apprentice: config.premium_apprentice_role,
adept: config.premium_adept_role,
expert: config.premium_expert_role,
master: config.premium_master_role,
legendary: config.premium_legendary_role,
patron: config.patron_role
}
})
const array = await client.shard.broadcastEval(async (c, { userId, apprentice, adept, expert, master, legendary, patron }) => {
let donor = '\❌'
let membership = 'None'
const server = c.guilds.cache.get('992937347094155356')
if (server) {
let member;
try {
member = await server.members.fetch(`${userId}`)
} catch (error) {
member = undefined
}
if (
member !== undefined &&
(
member.roles.cache.has(apprentice) ||
member.roles.cache.has(adept) ||
member.roles.cache.has(expert) ||
member.roles.cache.has(master) ||
member.roles.cache.has(legendary)
)
) {
donor = '\✅'
if (member.roles.cache.has(apprentice)) {
membership = 'Apprentice'
}
if (member.roles.cache.has(adept)) {
membership = 'Adept'
}
if (member.roles.cache.has(expert)) {
membership = 'Expert'
}
if (member.roles.cache.has(master)) {
membership = 'Master'
}
if (member.roles.cache.has(legendary)) {
membership = 'Legendary'
}
}
await server.members.fetch()
return { donor, membership };
}
return { donor, membership };
}, {
context: {
userId: interaction.user.id,
apprentice: config.premium_apprentice_role,
adept: config.premium_adept_role,
expert: config.premium_expert_role,
master: config.premium_master_role,
legendary: config.premium_legendary_role,
patron: config.patron_role
}
})
While having 3 shards, it worked completely as expected. Now that there's 4 shards, it always returns the ❌ and 'None' even when it shouldn't?
2 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 12/2/2022 in #djs-questions
How to get a server on Shard 1, from Shard 2?
How do I get a server on Shard 1, from Shard 2? I need to get a server on a different shard sometimes, to check if the user who ran the command has a role on my bot's support server:
let donor = '\❌'
let member;
try {
member = await server.members.fetch(`${interaction.user.id}`)
} catch (error) {
member = undefined
}
if (
member !== undefined &&
member.roles.cache.has(config.premium_teaser_role) ||
member.roles.cache.has(config.premium_gold_role) ||
member.roles.cache.has(config.premium_diamond_role) ||
member.roles.cache.has(config.premium_ruby_role)
) {
donor = '\✅'
}
await server.members.fetch()
let donors = await server.roles.cache.get(config.patron_role).members.size
let donor = '\❌'
let member;
try {
member = await server.members.fetch(`${interaction.user.id}`)
} catch (error) {
member = undefined
}
if (
member !== undefined &&
member.roles.cache.has(config.premium_teaser_role) ||
member.roles.cache.has(config.premium_gold_role) ||
member.roles.cache.has(config.premium_diamond_role) ||
member.roles.cache.has(config.premium_ruby_role)
) {
donor = '\✅'
}
await server.members.fetch()
let donors = await server.roles.cache.get(config.patron_role).members.size
10 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 10/31/2022 in #djs-questions
Shard Presence
How do I change my client's Presence on each Shard saying THAT Shard? So in guilds with e.g. Shard id 1, it will say "Shard: 1".
3 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 10/30/2022 in #djs-questions
Problems after having 2 shards
let server = client.guilds.cache.get('server_id')
let category = server.channels.cache.find(c => c.id === 'category_id' && c.type == Discord.ChannelType.GuildCategory);
let server = client.guilds.cache.get('server_id')
let category = server.channels.cache.find(c => c.id === 'category_id' && c.type == Discord.ChannelType.GuildCategory);
TypeError: Cannot read properties of undefined (reading 'channels') My bot now uses two shards, so it's also running the ready event twice. What's a fix for this?
15 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 8/30/2022 in #djs-questions
Someone forgot to update the docs
I don't know where I'm supposed to post this, but I think someone forgot to update https://discord.js.org/#/docs/discord.js/stable/class/VoiceState?scrollTo=setSuppressed As it's not longer 'guild.me.setSuppressed' 😄
3 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 8/30/2022 in #djs-voice
TypeError Cannot read properties of undefined (reading 'voice')
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
})
await guild.me.voice.setSuppressed(false)
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
})
await guild.me.voice.setSuppressed(false)
When trying to speak in the stage channel, it shows up with this error: TypeError Cannot read properties of undefined (reading 'voice')? Edit: I just realised it's now <guild>.members.me 😄
2 replies
DIAdiscord.js - Imagine an app
Created by Iced Queen on 8/7/2022 in #djs-questions
How do I loop an audio?
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
})

let audio = pathName + 'yeay.mp3'

let player = createAudioPlayer()
let resource = createAudioResource(audio)

player.play(resource)
connection.subscribe(player)

player.on(AudioPlayerStatus.Idle, () => {

player.play(resource)

})
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
})

let audio = pathName + 'yeay.mp3'

let player = createAudioPlayer()
let resource = createAudioResource(audio)

player.play(resource)
connection.subscribe(player)

player.on(AudioPlayerStatus.Idle, () => {

player.play(resource)

})
I tried this but without luck. It plays fine the first time, but doesn't loop the audio which is what I want. How can I do that? The error I am getting is: Error: Cannot play a resource that has already ended.
3 replies