pal3st1na
pal3st1na
DIAdiscord.js - Imagine an app
Created by pal3st1na on 12/13/2024 in #djs-questions
search function
Can the discord bot use the discord search function? For example, from the user:, after:, in the channel: Can you write an example code? I will be grateful! My code below works, though not exactly as it should, but if, for example, there are about 10 thousand messages in the channel, then it will take a very long time(
const START_DATE = new Date('2024-12-11');

async function fetchAllMessages(channelId, userId) {
const channel = await interaction.client.channels.fetch(channelId);
let allMessages = [];
let lastMessageId = null;

while (true) {
const options = { limit: 100 };
if (lastMessageId) {
options.before = lastMessageId;
}

const fetchedMessages = await channel.messages.fetch(options);
const messagesArray = Array.from(fetchedMessages.values());
const userMessages = messagesArray.filter(msg => msg.createdAt >= START_DATE && msg.author.id === userId);
allMessages = allMessages.concat(userMessages);

if (fetchedMessages.size < 100 || userMessages.length === 0) {
break;
}

lastMessageId = messagesArray[messagesArray.length - 1].id;
}

return allMessages;
}
const START_DATE = new Date('2024-12-11');

async function fetchAllMessages(channelId, userId) {
const channel = await interaction.client.channels.fetch(channelId);
let allMessages = [];
let lastMessageId = null;

while (true) {
const options = { limit: 100 };
if (lastMessageId) {
options.before = lastMessageId;
}

const fetchedMessages = await channel.messages.fetch(options);
const messagesArray = Array.from(fetchedMessages.values());
const userMessages = messagesArray.filter(msg => msg.createdAt >= START_DATE && msg.author.id === userId);
allMessages = allMessages.concat(userMessages);

if (fetchedMessages.size < 100 || userMessages.length === 0) {
break;
}

lastMessageId = messagesArray[messagesArray.length - 1].id;
}

return allMessages;
}
7 replies
DIAdiscord.js - Imagine an app
Created by pal3st1na on 12/3/2024 in #djs-questions
Ephemeral messages
My problem is that the error message is Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. and not only DiscordAPIError[40060]: Interaction has already been recognized. they happen because of my ephemeral messages, for example, I have a main message with several buttons, all buttons send messages from ephemeral, ephemeral messages have a couple more buttons, for example, to scroll through the rules pages, if I scroll to some and close the ephemeral message that is visible only to me. The next time you open it, it will give you similar errors, is there any way to fix this?
24 replies