Swyftey
Swyftey
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Swyftey on 11/17/2024 in #djs-questions
What is the best way to detect a change in server ownership when the bot happens to be offline?
Hi, I am using Discord.JS and am trying to figure out how I might change a server in my database's owner_id field when the owner id is found to be different. Here is an example:
// ClientReady.ts

try {
// Get database servers (my api)
const databaseServersResponse: Response = await ApiHandler.get(`http://api:${EnvHandler.get("API_PORT")}/servers`);
const databaseServers: Server[] = (await databaseServersResponse.json() as APIResponse).data?.servers;

// Get servers bot is in (discord.js)
const botServers: Record<string, any>[] = await ShardingHandler.getAllGuilds(botClient);
const botServerIds: string[] = botServers.map((server: Record<string, any>) => server.id);

// Get servers bot is not in
const notFoundServers: Server[] = databaseServers.filter((server: Server) => !botServerIds.includes(server.id));

for (const foundServer of botServers) {
await ApiHandler.patch(`http://api:${EnvHandler.get("API_PORT")}/users/${foundServer.ownerId}/servers/${foundServer.id}`, { has_bot: true });
}


// Here is where I am struggling. I don't think I can get the new owner id, because the bot is not in the guild.
for (const notFoundServer of notFoundServers) {
await ApiHandler.patch(`http://api:${EnvHandler.get("API_PORT")}/users/${notFoundServer.owner_id}/servers/${notFoundServer.id}`, { has_bot: false });
}

console.log("Successfully initizalied the bot and updated all necessary data.");
// ClientReady.ts

try {
// Get database servers (my api)
const databaseServersResponse: Response = await ApiHandler.get(`http://api:${EnvHandler.get("API_PORT")}/servers`);
const databaseServers: Server[] = (await databaseServersResponse.json() as APIResponse).data?.servers;

// Get servers bot is in (discord.js)
const botServers: Record<string, any>[] = await ShardingHandler.getAllGuilds(botClient);
const botServerIds: string[] = botServers.map((server: Record<string, any>) => server.id);

// Get servers bot is not in
const notFoundServers: Server[] = databaseServers.filter((server: Server) => !botServerIds.includes(server.id));

for (const foundServer of botServers) {
await ApiHandler.patch(`http://api:${EnvHandler.get("API_PORT")}/users/${foundServer.ownerId}/servers/${foundServer.id}`, { has_bot: true });
}


// Here is where I am struggling. I don't think I can get the new owner id, because the bot is not in the guild.
for (const notFoundServer of notFoundServers) {
await ApiHandler.patch(`http://api:${EnvHandler.get("API_PORT")}/users/${notFoundServer.owner_id}/servers/${notFoundServer.id}`, { has_bot: false });
}

console.log("Successfully initizalied the bot and updated all necessary data.");
If there isn't a way around this to changing the owner_id, what should I do? I'd rather a user who once owned a server (which is added to my database) not have access to it if they are no longer the owner.
12 replies
DDeno
Created by Swyftey on 11/4/2024 in #help
Deno 2.0 can't find .pem files even with --allow-read?
No description
3 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 11/2/2024 in #djs-questions
What is the best way to handle components when they've been timed out?
Hi, I'm sorry, I've probably asked this question a long time ago but have forgotten the answer as it has been a minute. What is the best way to go about timing buttons/components out? For example, a 60-second collector is started when a command is ran. When the 60 seconds are up, the buttons either disable or (what I'd prefer) have a different custom ID so that an error reply shows if the ID says the button is disabled. Also, what should be done (if anything) for when let's say the bot goes offline during the time a collector is running, how does the button disable/become timed out then? Thanks for any help.
5 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 10/30/2024 in #djs-questions
Embed Builder Not Defined When Using BroadcastEval
No description
53 replies
DDeno
Created by Swyftey on 10/29/2024 in #help
Next.JS with Deno 2.0 has "hydration" error after creation.
No description
11 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 10/24/2024 in #djs-questions
Discord slash command(s) deleting itself. (Sorry closed last post too early)
No description
53 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 10/24/2024 in #djs-questions
Why might a slash command delete itself after one use?
No description
19 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 10/20/2024 in #djs-questions
Sharding questions.
Hi. I am building a Discord bot which I can anticipate will eventually be in more than 2500 guilds pretty quick. I have a few questions about sharding which I am looking to have answered, any help is greatly appreciated: 1. Is it best to prepare and set up sharding for the bot now while I can? 2. Once the sharding manager is created, do I have to go back into my code (such as commands) and change it to work with all shards? Or does that depend on if the command should affect other guilds, for example? 3. What are the main use cases for using commands such as .broadcastEval() to communicate to all shards? Thanks!
33 replies
CDCloudflare Developers
Created by Swyftey on 10/13/2024 in #general-help
CF-Connecting-IP header is missing?
Hi. I need this header for the IP so that I can secure my Cloudflare worker. Why might I not be seeing this header? If it helps, I am using nginx proxy manager to host. The transform setting to remove the header is already disabled.
41 replies
DDeno
Created by Swyftey on 9/30/2024 in #help
Deno 2.0 displaying red-line errors in my typescript code, but they were non-breaking?
Hi! I'd like to use Deno for the integrated TypeScript and other useful features, but I had enough of the program (I think it was the vscode extension) showing some of my code as a deno-ts error when the project would run fine. It's been really weird because I'll try to fix the error, and whether I fix it or not, the red line ends up going away on its own eventually. It's been very iffy. Also, some types from my needed npm modules do not exist as they do in node.js, how can I solve that? How can I fix this so I can possibly go back to using deno?
2 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
No description
41 replies
CC#
Created by Swyftey on 9/17/2024 in #help
✅ ASP.NET Core SSL not working.
No description
75 replies
CDCloudflare Developers
Created by Swyftey on 7/29/2024 in #pages-help
I'm in a 'redirect loop' trying to use page domain with nginx.
No description
1 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 7/8/2024 in #djs-questions
Can the REST class be used to work with global rate limits (make sure you don't throttle)?
No description
3 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 7/8/2024 in #djs-questions
How can I make sure slash commands are only added/registered once?
I was adding and removing my bot from my server once for testing purposes and recently ran into the "Interaction already acknowledged" error. I fixed it by once again re-adding my bot, but how can I prevent slash commands from being added if they already exist or just prevent this in general?
11 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 6/18/2024 in #djs-questions
Just double checking to be extra sure: Do ALL DiscordJS fetch methods check the cache first?
I'm trying to understand if I should still make my own cache module, or if I can (or if it is *okay * to) trust that the cache will be called first before attempting to use discord's API. For example, just calling guild.fetchWebhooks() upon an event that is fired, or checking my own cache module to see if the webhook is found before calling that.
3 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 6/12/2024 in #djs-questions
Does DiscordJS support activities/activity creation? If not, will it in the future?
Title displays question. Sorry if this is regularly asked, couldn't find.
10 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 6/3/2024 in #djs-questions
Role Select Menu not clearing/refreshing?
I swear it was working before. The input will not clear. Once the "next-button" is clicked, the message should update and the select menu should not display the previous inputs. The page number is correct and the data to set/display for the role select menu is correct as well.
case "next-button": {
if (currentConfig.index < info.pages.length-1) {
currentConfig.index += 1
currentConfig.page = info.pages[currentConfig.index]

await component.update({
embeds: [embeds.embed({
title: currentConfig.page.embed.title,
color: currentConfig.page.embed.color,
fields: currentConfig.page.embed.fields
})],
components: await setComponents(currentConfig)
});
}
break;
}
case "next-button": {
if (currentConfig.index < info.pages.length-1) {
currentConfig.index += 1
currentConfig.page = info.pages[currentConfig.index]

await component.update({
embeds: [embeds.embed({
title: currentConfig.page.embed.title,
color: currentConfig.page.embed.color,
fields: currentConfig.page.embed.fields
})],
components: await setComponents(currentConfig)
});
}
break;
}
6 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 5/30/2024 in #djs-questions
Is it possible to check if component timed out AFTER it has timed out?
For example, when a message is sent with a select-menu component:
try {
const select = await initialReply.awaitMessageComponent({ filter: i => i.user.id === interaction.user.id, time: 15_000 });
} catch (error) {
console.log(`[setup.js]`, error);
// Instead of making a chat message appear stating the command timed out automatically, send the message if the user continues to try using the component within the message (if it exists)
}
try {
const select = await initialReply.awaitMessageComponent({ filter: i => i.user.id === interaction.user.id, time: 15_000 });
} catch (error) {
console.log(`[setup.js]`, error);
// Instead of making a chat message appear stating the command timed out automatically, send the message if the user continues to try using the component within the message (if it exists)
}
18 replies
DIAdiscord.js - Imagine an app
Created by Swyftey on 5/29/2024 in #djs-questions
Client.Users.Fetch(UserId) erroring, stating UserId is null when it is not.
No description
2 replies