GoatSniff
GoatSniff
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
Hey, I'm not too sure why but when I check the member cache of a specific guild, I can only see 1 user (My bot account itself) but not other users. My guild has two users in it, one is the bot and one is myself
const guild = await client.guilds.cache.get(process.env.DISCORD_GUILD_ID);
console.log(guild); // Correctly finds guild
const member = await guild.members.cache.get(discordID);
console.log(guild.members.cache) // Shows Collection(1) with my bot only
const guild = await client.guilds.cache.get(process.env.DISCORD_GUILD_ID);
console.log(guild); // Correctly finds guild
const member = await guild.members.cache.get(discordID);
console.log(guild.members.cache) // Shows Collection(1) with my bot only
The discord account has access to view the members because I use this same bot account to do this in another script I run. My intents also match the working bot script I have:
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildIntegrations] });
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildIntegrations] });
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
Hey, I started creating a discord bot. It returns a link for the user to click on but it's pretty ugly so i wanted to move over to a button, but when I do this, I am not getting any errors in my console, but running the slash command gives me "An error has occurred." in discord. Currently this works fine: await interaction.reply({ content: 'Please log in on our website to sync your account: ' + url}); I copied the official discord.js example with plain strings to keep things simple but even that won't work. If I replace the above line with this I'll get the error:
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Danger);

const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);

const row = new ActionRowBuilder()
.addComponents(cancel, confirm);

await interaction.reply({
content: `Are you sure?`,
components: [row],
});
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Danger);

const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);

const row = new ActionRowBuilder()
.addComponents(cancel, confirm);

await interaction.reply({
content: `Are you sure?`,
components: [row],
});
16 replies