fedpep
fedpep
DIAdiscord.js - Imagine an app
Created by fedpep on 12/4/2024 in #djs-questions
Thread .fetchArchived() doesn't return all the archived threads even if those are public
Hey there, I'm using the .fetchArchived() function to get all the archived threads in a forum but it looks like the function returns only a limited number of results. I had a look at the documentation but from my understanding adding the option fetchAll can be used only if the type is set to private which is not my case as all the threads are public. As you can see in the code I also didn't set a specific limit because I want to export all the archived threads but it looks like I can only get 50 of them.
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });

const guild = interaction.guild;

try {
const inputChannel = await interaction.options.getChannel('channel');
// Get the active threads
let channel = await inputChannel.threads.fetch();
// Get the archived threads
let archived = await inputChannel.threads.fetchArchived();

let posts = [];

archived.threads.forEach(async post => {
posts.push(post);
})

console.log(posts.length);
}
catch(e) {
console.log(e);
await interaction.editReply({content: `Something went wrong while processing the interaction`});
}
}
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });

const guild = interaction.guild;

try {
const inputChannel = await interaction.options.getChannel('channel');
// Get the active threads
let channel = await inputChannel.threads.fetch();
// Get the archived threads
let archived = await inputChannel.threads.fetchArchived();

let posts = [];

archived.threads.forEach(async post => {
posts.push(post);
})

console.log(posts.length);
}
catch(e) {
console.log(e);
await interaction.editReply({content: `Something went wrong while processing the interaction`});
}
}
3 replies
DIAdiscord.js - Imagine an app
Created by fedpep on 10/21/2024 in #djs-questions
Fetch all reactions from a message but without cache
Hey there, is that a way to fetch all reactions attached to a message without using the cache function? This is my current code
const mess = await i.fetchStarterMessage().catch(() => null);

if(mess != null) {
const react = mess.reactions.cache.forEach(async (reaction) => {
const emojiName = reaction._emoji.name
const emojiCount = reaction.count
});
}
const mess = await i.fetchStarterMessage().catch(() => null);

if(mess != null) {
const react = mess.reactions.cache.forEach(async (reaction) => {
const emojiName = reaction._emoji.name
const emojiCount = reaction.count
});
}
I looked for examples online and read through the documentation but I only found the "cache" function.
13 replies
DIAdiscord.js - Imagine an app
Created by fedpep on 10/14/2024 in #djs-questions
How can I get an array of all the posts in a forum?
Hey there, I looked at the documentation but couldn't find anything regarding forum channels. I want to create a Slash Command that accepts a forum channel as input and then returns an array of all the posts that are in that forum. Any help would be much appreciated
25 replies
DIAdiscord.js - Imagine an app
Created by fedpep on 9/17/2024 in #djs-questions
awaitMessageComponent doesn't wait the set time
Hey there, I'm following the guide but I can't figure out why awaitMessageComponent doesn't wait for the set time. Here's my code:
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, PermissionFlagsBits } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Testing commands.')
.addChannelOption(option =>
option.setName('from')
.setDescription('Move members from this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.addChannelOption(option =>
option.setName('to')
.setDescription('Move members to this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),

async execute(interaction) {

const from = interaction.options.getChannel('from');
const to = interaction.options.getChannel('to');

// Build confirmation buttons interaction
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Success);

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

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

await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});

// The filter applied here ensures that only the user who triggered the original interaction can use the buttons.
const collectorFilter = i => i.user.id === interaction.user.id;

try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 });
console.log("Success");
} catch (e) {
await interaction.editReply({ content: 'Confirmation not received within 1 minute, cancelling', components: [] });
}

},
};
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, PermissionFlagsBits } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Testing commands.')
.addChannelOption(option =>
option.setName('from')
.setDescription('Move members from this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.addChannelOption(option =>
option.setName('to')
.setDescription('Move members to this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),

async execute(interaction) {

const from = interaction.options.getChannel('from');
const to = interaction.options.getChannel('to');

// Build confirmation buttons interaction
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Success);

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

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

await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});

// The filter applied here ensures that only the user who triggered the original interaction can use the buttons.
const collectorFilter = i => i.user.id === interaction.user.id;

try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 });
console.log("Success");
} catch (e) {
await interaction.editReply({ content: 'Confirmation not received within 1 minute, cancelling', components: [] });
}

},
};
Here the intents in index.js
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
] });
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
] });
Any help would be much appreciated
14 replies