Frosttide
Frosttide
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
since all the other commands work
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
i thought idk, maybe im doing something stupid that im not seeing
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
No description
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
but it looks similar to what i did
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
he just gave me this template
interaction: {
type: ApplicationCommandType.ChatInput,
description: 'Show a list of commands',
options: [
{
name: 'command',
description: 'The command to get help for',
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: 'type',
description: 'The type of command to get help for (slash, user, message) - defaults to slash',
type: ApplicationCommandOptionType.String,
choices: [
{name: 'slash', value: 'chat'},
{name: 'user', value: 'user'},
{name: 'message', value: 'message'},
],
required: false,

}
],
},
interaction: {
type: ApplicationCommandType.ChatInput,
description: 'Show a list of commands',
options: [
{
name: 'command',
description: 'The command to get help for',
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: 'type',
description: 'The type of command to get help for (slash, user, message) - defaults to slash',
type: ApplicationCommandOptionType.String,
choices: [
{name: 'slash', value: 'chat'},
{name: 'user', value: 'user'},
{name: 'message', value: 'message'},
],
required: false,

}
],
},
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
I did , I did ;x
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
is this what youre looking for?
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
export async function getInteractionsOfType<
TType extends keyof BackendInteractionType
>(type: TType): Promise<Record<string, BackendInteractionType[TType]>> {
const interactionTypeDir = path.join(interactionsDir, type);
console.log(
`Processing ${type} commands...\nDirectory: ${interactionTypeDir}`
);

try {
await fs.access(interactionTypeDir);
} catch (e) {
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
console.log(`No ${type} commands found.`);
return {};
} else throw e;
}

const files = (await fs.readdir(interactionTypeDir, { withFileTypes: true }))
.map((file) =>
file.isFile()
? file.name.endsWith(extension) && file.name
: file.isDirectory() && file.name
)
.filter((file) => file) as string[];
const interactions = await Promise.all(
files.map((file) => getSingleInteraction(type, file))
);

const interactionsObj: Record<string, BackendInteractionType[TType]> = {};
for (const interaction of interactions)
interactionsObj[interaction.interaction.name] = interaction;

return interactionsObj;
}
export async function getInteractionsOfType<
TType extends keyof BackendInteractionType
>(type: TType): Promise<Record<string, BackendInteractionType[TType]>> {
const interactionTypeDir = path.join(interactionsDir, type);
console.log(
`Processing ${type} commands...\nDirectory: ${interactionTypeDir}`
);

try {
await fs.access(interactionTypeDir);
} catch (e) {
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
console.log(`No ${type} commands found.`);
return {};
} else throw e;
}

const files = (await fs.readdir(interactionTypeDir, { withFileTypes: true }))
.map((file) =>
file.isFile()
? file.name.endsWith(extension) && file.name
: file.isDirectory() && file.name
)
.filter((file) => file) as string[];
const interactions = await Promise.all(
files.map((file) => getSingleInteraction(type, file))
);

const interactionsObj: Record<string, BackendInteractionType[TType]> = {};
for (const interaction of interactions)
interactionsObj[interaction.interaction.name] = interaction;

return interactionsObj;
}
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
Sorry , its written in TS and I know almost nothing about TS.
export async function getAllInteractions() {
const [chat, user, message] = await Promise.all([
getInteractionsOfType("chat"),
getInteractionsOfType("user"),
getInteractionsOfType("message"),
]);

return { chat, user, message };
}

const thisFile = fileURLToPath(import.meta.url);
const interactionsDir = path.dirname(thisFile);
const extension = path.extname(thisFile);
export async function getAllInteractions() {
const [chat, user, message] = await Promise.all([
getInteractionsOfType("chat"),
getInteractionsOfType("user"),
getInteractionsOfType("message"),
]);

return { chat, user, message };
}

const thisFile = fileURLToPath(import.meta.url);
const interactionsDir = path.dirname(thisFile);
const extension = path.extname(thisFile);
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
Im not the one who wrote the code, but I believe this is how they are being used
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
async function sendInteraction(interaction: Interaction) {
const isChat = interaction.isChatInputCommand();
const isUser = interaction.isUserContextMenuCommand();
const isMessage = interaction.isMessageContextMenuCommand();

const isCommand = isChat || isUser || isMessage;

if (!isCommand) return; // Don't handle these types of interactions here

const command = isChat ? interactionsObj.chat[interaction.commandName]
: isUser ? interactionsObj.user[interaction.commandName]
: isMessage ? interactionsObj.message[interaction.commandName]
: null;
try {
if (command)
await command.execute(interaction as any); // Cast to `any` here because TypeScript can't figure out the correct parameter type for `execute`
else {
console.warn(new Error("Unbound Interaction"), { interaction });
await interaction[
interaction.deferred ? "editReply"
: interaction.replied ? "followUp"
: "reply"
]({
content: `ERROR: Unbound interaction (we can't seem to find code to handle what you asked for!)`,
ephemeral: true,
files: [{
attachment: Buffer.from(stringifyJson(interaction, 4)),
name: "interaction.json",
}],
});
}
} catch (error) {
await catchInteractionErrors(error, interaction);
}
}

client.on("interactionCreate", sendInteraction);
async function sendInteraction(interaction: Interaction) {
const isChat = interaction.isChatInputCommand();
const isUser = interaction.isUserContextMenuCommand();
const isMessage = interaction.isMessageContextMenuCommand();

const isCommand = isChat || isUser || isMessage;

if (!isCommand) return; // Don't handle these types of interactions here

const command = isChat ? interactionsObj.chat[interaction.commandName]
: isUser ? interactionsObj.user[interaction.commandName]
: isMessage ? interactionsObj.message[interaction.commandName]
: null;
try {
if (command)
await command.execute(interaction as any); // Cast to `any` here because TypeScript can't figure out the correct parameter type for `execute`
else {
console.warn(new Error("Unbound Interaction"), { interaction });
await interaction[
interaction.deferred ? "editReply"
: interaction.replied ? "followUp"
: "reply"
]({
content: `ERROR: Unbound interaction (we can't seem to find code to handle what you asked for!)`,
ephemeral: true,
files: [{
attachment: Buffer.from(stringifyJson(interaction, 4)),
name: "interaction.json",
}],
});
}
} catch (error) {
await catchInteractionErrors(error, interaction);
}
}

client.on("interactionCreate", sendInteraction);
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
const interactionsObj = await interactions;
const interactionsToSet = await rawInteractions;

if (interactionsToSet.global)
client.application?.commands.set(interactionsToSet.global);

if (interactionsToSet.guilds)
for (const guild in interactionsToSet.guilds){
console.log(`Setting guild ${guild} commands...`);
client.guilds.fetch(guild)
.then((g) => g.commands.set(interactionsToSet.guilds[guild]!) )
.catch((e) => console.error(`Error while setting guild ${guild} commands`, e));
}
const interactionsObj = await interactions;
const interactionsToSet = await rawInteractions;

if (interactionsToSet.global)
client.application?.commands.set(interactionsToSet.global);

if (interactionsToSet.guilds)
for (const guild in interactionsToSet.guilds){
console.log(`Setting guild ${guild} commands...`);
client.guilds.fetch(guild)
.then((g) => g.commands.set(interactionsToSet.guilds[guild]!) )
.catch((e) => console.error(`Error while setting guild ${guild} commands`, e));
}
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
but options just dont show
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
console.log statements work aswell
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
so I assume the file is being parsed correctly
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
in discord
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
well I changed giveaway to giveawayawd and the change was reflected
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
I run the bot locally on my machine
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
My collegue wrote the import script, its kinda long
26 replies
DIAdiscord.js - Imagine an app
Created by Frosttide on 1/25/2024 in #djs-questions
Options missing from slash command.
heres how its setup
interaction: {
type: ApplicationCommandOptionType.Subcommand,
description: "Create a poll.",
options: [
{
name: "question",
description: "poll question",
type: ApplicationCommandOptionType.String,
required: true,
},
//removed the other options for brevity
] as NonNullable<InteractionDefinition<ApplicationCommandSubCommandData, true>["interaction"]["options"]>,
},
interaction: {
type: ApplicationCommandOptionType.Subcommand,
description: "Create a poll.",
options: [
{
name: "question",
description: "poll question",
type: ApplicationCommandOptionType.String,
required: true,
},
//removed the other options for brevity
] as NonNullable<InteractionDefinition<ApplicationCommandSubCommandData, true>["interaction"]["options"]>,
},
26 replies