Phil
Phil
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Phil on 4/14/2025 in #djs-questions
How to handle cancellations on individual reoccurring events?
I have a simple bot to clone events and announce them. a new partnership now uses reoccurring events, so i got to fix them today. I had to notice today tho that DJS does not handle cancellations of individual events, unless i don't quite understand how that works. So before I open up a feature request, I was curious, if i was missing something. I tried checking for GuildScheduledEvent#isCanceled but that does not work and canceling the whole event calls a different event (guildScheduledEventDelete) and not guildScheduledEventUpdate. But from what I can see on the GuildScheduledEvent - Structure in the docs it doesn't seem to have any fields related to these kinds of edge cases. Source Code/Repo with relevant line: https://github.com/FlippedCodes/event-cloner/blob/975cb4aaf753d9db8b9bc95c44f7c723f36aa16e/index.js#L126
5 replies
HHono
Created by Phil on 5/31/2024 in #help
[zod, bun]#openapi async/await doesn't work
This ossue was previously on https://discord.com/channels/1011308539819597844/1012485912409690122/1242558525012709539, but I was advised to open it here. here is a noob question. Im quite new to TS, bun and Hono with Zod. I cant make sense of why TS is screaming at me in the first line with async
apps.openapi(routeGetApp, async (c) => {
~~~~~~~~~~~~~~
try {
const { identifier } = c.req.valid('param');
const result = await db.query.app.findFirst({
where: eq(app.name, identifier),
with: { feature: true },
});
if (!result) return c.notFound();
console.log(result);
return c.json({
id: result.id,
identifier: result.name,
features: {
featureX: result.feature.deleteMessage,
featureY: result.feature.inviteLinks,
},
});
} catch (error) { return c.json(error, 500); }
});
apps.openapi(routeGetApp, async (c) => {
~~~~~~~~~~~~~~
try {
const { identifier } = c.req.valid('param');
const result = await db.query.app.findFirst({
where: eq(app.name, identifier),
with: { feature: true },
});
if (!result) return c.notFound();
console.log(result);
return c.json({
id: result.id,
identifier: result.name,
features: {
featureX: result.feature.deleteMessage,
featureY: result.feature.inviteLinks,
},
});
} catch (error) { return c.json(error, 500); }
});
the error reads
Argument of type '(c: Context<Env, "/:identifier", { in: { param: { identifier?: string; }; }; out: { param: { identifier?: string; }; }; }>) => Promise<Response>' is not assignable to parameter of type 'Handler<Env, "/:identifier", { in: { param: { identifier?: string; }; }; out: { param: { identifier?: string; }; }; }, HandlerTypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>>'.
Type 'Promise<Response>' is not assignable to type 'HandlerTypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>'.
Type 'Promise<Response>' is not assignable to type 'Promise<TypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>>'.
Type 'Response' is missing the following properties from type 'TypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>': data, formatts(2345)
Argument of type '(c: Context<Env, "/:identifier", { in: { param: { identifier?: string; }; }; out: { param: { identifier?: string; }; }; }>) => Promise<Response>' is not assignable to parameter of type 'Handler<Env, "/:identifier", { in: { param: { identifier?: string; }; }; out: { param: { identifier?: string; }; }; }, HandlerTypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>>'.
Type 'Promise<Response>' is not assignable to type 'HandlerTypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>'.
Type 'Promise<Response>' is not assignable to type 'Promise<TypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>>'.
Type 'Response' is missing the following properties from type 'TypedResponse<{ id?: number; identifier?: string; features?: { featureX?: boolean; featureY?: number; }; }>': data, formatts(2345)
I think im returning my result wrong? it works fine, when returning it normally without my DB stuff and async/await I havent tried running it with that error.. but I kind of want to resolve it first regardless.
10 replies
DTDrizzle Team
Created by Phil on 4/9/2024 in #help
Issues with the "with" parameter
No description
1 replies
DIAdiscord.js - Imagine an app
Created by Phil on 2/12/2023 in #djs-questions
How to handle message deletions when the message in question is already gone?
Helo! I ran into an issue where a message was already deleted and i cant get the bot to not throw an error "Unknown Message".
const { PermissionsBitField } = require('discord.js');

const BridgedChannel = require('../../database/models/bridgedChannel');

const MessageLink = require('../../database/models/messageLink');

async function getMessages(messageID) {
// check DB for messageID and get messageInstanceID
const messageInstanceID = await MessageLink.findOne({ attributes: ['messageInstanceID'], where: { messageID } }).catch(ERR);
if (!messageInstanceID) return null;
// get all messageIDs
const coreID = messageInstanceID.messageInstanceID;
const allMessageIDs = await MessageLink.findAll({ attributes: ['messageID', 'channelID'], where: { messageInstanceID: coreID } }).catch(ERR);
MessageLink.destroy({ where: { messageInstanceID: coreID } });
return allMessageIDs;
}

// Deletes all messages in every channel, if its deleted in one
module.exports.run = async (message) => {
// check if channel is part of service
if (!await BridgedChannel.findOne({ attributes: ['channelID'], where: { channelID: message.channel_id } }).catch(ERR)) return;

const allMessageIDs = await getMessages(message.id);
if (!allMessageIDs) return;

allMessageIDs.forEach(async (entry) => {
if (message.id === entry.messageID) return;
const channel = await client.channels.cache.get(entry.channelID);
// check if bot has permissions to delete messages
if (!channel.guild.members.me.permissionsIn(channel).has(PermissionsBitField.Flags.ManageMessages)) return;
// existence check attempt
if (!await channel.messages.fetch(entry.messageID)) return;
channel.messages.delete(entry.messageID);
});
};
const { PermissionsBitField } = require('discord.js');

const BridgedChannel = require('../../database/models/bridgedChannel');

const MessageLink = require('../../database/models/messageLink');

async function getMessages(messageID) {
// check DB for messageID and get messageInstanceID
const messageInstanceID = await MessageLink.findOne({ attributes: ['messageInstanceID'], where: { messageID } }).catch(ERR);
if (!messageInstanceID) return null;
// get all messageIDs
const coreID = messageInstanceID.messageInstanceID;
const allMessageIDs = await MessageLink.findAll({ attributes: ['messageID', 'channelID'], where: { messageInstanceID: coreID } }).catch(ERR);
MessageLink.destroy({ where: { messageInstanceID: coreID } });
return allMessageIDs;
}

// Deletes all messages in every channel, if its deleted in one
module.exports.run = async (message) => {
// check if channel is part of service
if (!await BridgedChannel.findOne({ attributes: ['channelID'], where: { channelID: message.channel_id } }).catch(ERR)) return;

const allMessageIDs = await getMessages(message.id);
if (!allMessageIDs) return;

allMessageIDs.forEach(async (entry) => {
if (message.id === entry.messageID) return;
const channel = await client.channels.cache.get(entry.channelID);
// check if bot has permissions to delete messages
if (!channel.guild.members.me.permissionsIn(channel).has(PermissionsBitField.Flags.ManageMessages)) return;
// existence check attempt
if (!await channel.messages.fetch(entry.messageID)) return;
channel.messages.delete(entry.messageID);
});
};
14 replies
DIAdiscord.js - Imagine an app
Created by Phil on 9/20/2022 in #djs-questions
Bug when using AttachmentBuilder.setSpoiler
I noticed, that it is not possible to set a attachments spoiler with .setSpoiler. I have been told to ask here first, before reporting to GitHub. I also tested the text branch, and it still seems to be there. Steps to reproduce: - use AttachmentBuilder - use a URL as the attachment argument - use setSpoiler function What should happen: Set the spoiler, so the file later gets marked that way in discord. What happens instead: Throws following error:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (/home/phil/Documents/GIT/gurglebot/lib/internal/errors.js:393:5)
at validateString (/home/phil/Documents/GIT/gurglebot/lib/internal/validators.js:161:11)
at parse (/home/phil/Documents/GIT/gurglebot/lib/path.js:1450:5)
at basename (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/util/Util.js:464:15)
at get spoiler [as spoiler] (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:85:12)
at AttachmentBuilder.setSpoiler (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:67:26)
at /home/phil/Documents/GIT/gurglebot/functions/ENGINE/contentWarning/COMPONENT/modal/repost.js:26:16
at /home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:174:14
at Function.from (<anonymous>)
at Collection.map (/home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:172:18) {code: 'ERR_INVALID_ARG_TYPE', stack: 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" …cordjs/collection/dist/collection.cjs:172:18)', message: 'The "path" argument must be of type string. Received undefined', toString: ƒ, Symbol(kIsNodeError): true}
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (/home/phil/Documents/GIT/gurglebot/lib/internal/errors.js:393:5)
at validateString (/home/phil/Documents/GIT/gurglebot/lib/internal/validators.js:161:11)
at parse (/home/phil/Documents/GIT/gurglebot/lib/path.js:1450:5)
at basename (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/util/Util.js:464:15)
at get spoiler [as spoiler] (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:85:12)
at AttachmentBuilder.setSpoiler (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:67:26)
at /home/phil/Documents/GIT/gurglebot/functions/ENGINE/contentWarning/COMPONENT/modal/repost.js:26:16
at /home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:174:14
at Function.from (<anonymous>)
at Collection.map (/home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:172:18) {code: 'ERR_INVALID_ARG_TYPE', stack: 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" …cordjs/collection/dist/collection.cjs:172:18)', message: 'The "path" argument must be of type string. Received undefined', toString: ƒ, Symbol(kIsNodeError): true}
32 replies