oyumly
oyumly
DIAdiscord.js - Imagine an app
Created by oyumly on 3/23/2025 in #djs-questions
Buttons with Discord RPC do not appear
const DiscordRPC = require('discord-rpc');
const clientId = '#';

const TrackerRPC = new DiscordRPC.Client({ transport: 'ipc' });

async function setActivity() {
if (!TrackerRPC) return;
TrackerRPC.setActivity({
details: 'Tracker ',
state: 'By Delta-data',
startTimestamp: Date.now(),
largeImageKey: 'angry-bee',
largeImageText: 'angry-bee',
smallImageKey: '#',
smallImageText: '##',
instance: false,
buttons: [
{
label: "Discord",
url: "#1"
},
{
label: "Telegram",
url: "#2"
}
],
});
}

TrackerRPC.on('ready', async () => {
setActivity();

setInterval(() => {
setActivity();
}, 15 * 1000);
});

TrackerRPC.login({ clientId }).catch(console.error);

module.exports = {
TrackerRPC,
setActivity
};
const DiscordRPC = require('discord-rpc');
const clientId = '#';

const TrackerRPC = new DiscordRPC.Client({ transport: 'ipc' });

async function setActivity() {
if (!TrackerRPC) return;
TrackerRPC.setActivity({
details: 'Tracker ',
state: 'By Delta-data',
startTimestamp: Date.now(),
largeImageKey: 'angry-bee',
largeImageText: 'angry-bee',
smallImageKey: '#',
smallImageText: '##',
instance: false,
buttons: [
{
label: "Discord",
url: "#1"
},
{
label: "Telegram",
url: "#2"
}
],
});
}

TrackerRPC.on('ready', async () => {
setActivity();

setInterval(() => {
setActivity();
}, 15 * 1000);
});

TrackerRPC.login({ clientId }).catch(console.error);

module.exports = {
TrackerRPC,
setActivity
};
5 replies
DIAdiscord.js - Imagine an app
Created by oyumly on 2/23/2025 in #djs-questions
The problem with shards
The bot was launched two days ago, it was on the host, it worked 24/7, in a single instance, but yesterday something happened and the bot suddenly died, and when it started, there were errors, although there were no incomplete sessions, etc. Other bots don't have such problems. I use the bot to synchronize users in the tg channel and the discord server.
Error: Not enough sessions remaining to spawn 1 shards; only 0 remaining; resets at 2025-02-23T21:04:34.120Z
at WebSocketManager.connect (C:\Users\ivale\Desktop\helper.oyumly\node_modules\@discordjs\ws\dist\index.js:1458:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WebSocketManager.connect (C:\Users\ivale\Desktop\helper.oyumly\node_modules\discord.js\src\client\websocket\WebSocketManager.js:200:5)
at async Client.login (C:\Users\ivale\Desktop\helper.oyumly\node_modules\discord.js\src\client\Client.js:228:7)
Error: Not enough sessions remaining to spawn 1 shards; only 0 remaining; resets at 2025-02-23T21:04:34.120Z
at WebSocketManager.connect (C:\Users\ivale\Desktop\helper.oyumly\node_modules\@discordjs\ws\dist\index.js:1458:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WebSocketManager.connect (C:\Users\ivale\Desktop\helper.oyumly\node_modules\discord.js\src\client\websocket\WebSocketManager.js:200:5)
at async Client.login (C:\Users\ivale\Desktop\helper.oyumly\node_modules\discord.js\src\client\Client.js:228:7)
10 replies
DIAdiscord.js - Imagine an app
Created by oyumly 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 oyumly 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