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