hippietrail
hippietrail
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
annoyingly today's café is less laggy/bursty so can't test it so far
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
i don't fully grok the ramifications. by returning null i change the inferred type into a nullable aka InteractionResponse<boolean> | null and i don't need to care what an InteractionResponse or the boolean in it mean?
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
i don't
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "ESNext.Array"],
"module": "NodeNext",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "nodenext",
"sourceMap": true
},
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "ESNext.Array"],
"module": "NodeNext",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "nodenext",
"sourceMap": true
},
"exclude": ["node_modules"]
}
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
just let foo = await interaction.deferReply().catch(e => { return null; })? seems that returns a InteractionResponse<boolean>
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
I've only used try/catch prior to this problem which I tracked down when I discovered .catch() which I don't yet have a feel for
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
i'm not quite expert level in js/ts yet. Not sure how to check for returning null from .catch
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 2/22/2024 in #djs-questions
How best to handle `unknown interaction` on `deferReply`
npm list discord.js
└── discord.js@14.14.1
node -v
v21.6.2
npm list discord.js
└── discord.js@14.14.1
node -v
v21.6.2
9 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 1/4/2024 in #djs-questions
How to add support for private slash commands
ah ok i just found that independently and it's working. this text made me wonder if it is a bit heavy handed
Guild-based deployment of commands is best suited for development and testing in your own personal server. Once you're satisfied that it's ready, deploy the command globally to publish it to all guilds that your bot is in.
but i guess not as it's basically a private bot for my friends and one server so thanks everyone!
13 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 1/4/2024 in #djs-questions
How to add support for private slash commands
13 replies
DIAdiscord.js - Imagine an app
Created by hippietrail on 1/4/2024 in #djs-questions
How to add support for private slash commands
i modified the deploy-commands.js from a Coding Train video to add support for multiple commands per module:
import { REST, Routes } from 'discord.js';
import { config } from 'dotenv';
import fs from 'node:fs';

config();

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter((file) => file.endsWith('.js'));

for (const file of commandFiles) {
const command = await import(`./commands/${file}`); // Using dynamic import
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());

if ('data2' in command && 'execute2' in command) {
commands.push(command.data2.toJSON());

if ('data3' in command && 'execute3' in command) {
commands.push(command.data3.toJSON());

if ('data4' in command && 'execute4' in command) {
commands.push(command.data4.toJSON());

if ('data5' in command && 'execute5' in command) {
commands.push(command.data5.toJSON());
}
}
}
}
} else {
console.log(`[WARNING] The command ${file} is missing a required "data" or "execute" property.`);
}
}

const rest = new REST().setToken(process.env.TOKEN);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(Routes.applicationGuildCommands(process.env.CLIENTID, process.env.SERVERID), {
body: commands,
});

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
import { REST, Routes } from 'discord.js';
import { config } from 'dotenv';
import fs from 'node:fs';

config();

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter((file) => file.endsWith('.js'));

for (const file of commandFiles) {
const command = await import(`./commands/${file}`); // Using dynamic import
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());

if ('data2' in command && 'execute2' in command) {
commands.push(command.data2.toJSON());

if ('data3' in command && 'execute3' in command) {
commands.push(command.data3.toJSON());

if ('data4' in command && 'execute4' in command) {
commands.push(command.data4.toJSON());

if ('data5' in command && 'execute5' in command) {
commands.push(command.data5.toJSON());
}
}
}
}
} else {
console.log(`[WARNING] The command ${file} is missing a required "data" or "execute" property.`);
}
}

const rest = new REST().setToken(process.env.TOKEN);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(Routes.applicationGuildCommands(process.env.CLIENTID, process.env.SERVERID), {
body: commands,
});

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
i only dug in and grokked enough to do my mods
13 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
but it seems to actually be less effort to use the old continuation method and both ways are equally fast. here's the great answer I got on Stack Overflow https://stackoverflow.com/a/77072098/527702
5 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
the answer is yes instead of
let (data, _) = try await URLSession.shared.data(for: request)
let (data, _) = try await URLSession.shared.data(for: request)
use
let (asyncBytes, response) = try await URLSession.shared.bytes(from: url)
let (asyncBytes, response) = try await URLSession.shared.bytes(from: url)
then you can read the bytes byte-by-byte or line-by-line or probably other ways
for try await byte in bytes {
for try await byte in bytes {
or
for try await lines in bytes.lines {
for try await lines in bytes.lines {
then you can report progress either for each one, or keep track of how many calls/bytes/lines/etc or time elapsed to decide how often report progress
5 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
I'm assuming i'm going to need a delegate. but so for i've only used those in gui apps and i haven't found an example yet how to make/use one for my case
5 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
the code I started with was using a semaphore and I either assumed or read that was the old way and these days I should use async/await. Other examples I can find are for GUI apps (I'm doing commandline); or they used RunLoop, which I also assumed would be outdated
5 replies
TSDThe Swift Den
Created by iwontchill on 9/4/2023 in #swift-development
How to Rename a Project/App in Xcode
The way I do it is to close the project in Xcode and open it in VSCode where I do a search and replace in files. Carefully.
3 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
Thanks. It's just for a toy project to help me learn my way around the UI so not a big deal. I will learn custom controls later.
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
You can see the bounding box for the slider I want aligned on the right edge of the window does not match the slider itself.
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
No description
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
Yes I could also get a vertical slider in the centre of the display, but being able to align it like any normal control was well beyond my abilities as a newcomer.
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
Yes I found that one. Two answers involve custom slider libraries which will tend to have differences from the standard ones. The other one is much more promising involving swapping horizontal and vertical fields, but unlike native horizontal ones you have to pass the values in for those fields. And the newest comment on it says it doesn't work anymore. I've concluded there isn't really a native solution and it's intentional. At first I thought they designed it so you would "just" rotate it, but now I can see there is no "just" (-:
25 replies