Resident Of Prey
Resident Of Prey
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Resident Of Prey on 5/6/2024 in #djs-questions
AutoComplete Problem
before:-
async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused();

try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue));

await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
},
async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused();

try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue));

await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
},
after code:-
async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused(true);
switch (focusedValue.name) {
case "tag":
try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue.name));

await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
break;
case "hidden":
const choices = ["True", "False"];

await interaction.respond(
choices.map((choice) => ({ name: choice, value: choice }))
);
break;
default:
break;
}
},
async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused(true);
switch (focusedValue.name) {
case "tag":
try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue.name));

await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
break;
case "hidden":
const choices = ["True", "False"];

await interaction.respond(
choices.map((choice) => ({ name: choice, value: choice }))
);
break;
default:
break;
}
},
the autocomplete option named tag does not show any options, it used to show earlier but then i added the hidden option and a switch statement then it stopped working
4 replies
DIAdiscord.js - Imagine an app
Created by Resident Of Prey on 2/5/2024 in #djs-questions
collector problems and error
code:-
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(bttn1, bttn2);

const reply = await interaction.reply({
content: "Proceed Ban?",
components: [row]
})
const collector = reply.createMessageComponentCollector({ componentType: ComponentType.Button })
collector.on("collect", async (i: ButtonInteraction) => {
switch (i.customId) {
case "confirmBan": {
if (i.user.id !== interaction.user.id) {
return await i.reply({
content: "You are not permitted to use this button!",
ephemeral: true
})
}
await interaction.guild?.bans.create(user)
await i.update({
content: `Confirmed ban for ${user}\nThey are gone!`,
components: []
})
}
break;
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(bttn1, bttn2);

const reply = await interaction.reply({
content: "Proceed Ban?",
components: [row]
})
const collector = reply.createMessageComponentCollector({ componentType: ComponentType.Button })
collector.on("collect", async (i: ButtonInteraction) => {
switch (i.customId) {
case "confirmBan": {
if (i.user.id !== interaction.user.id) {
return await i.reply({
content: "You are not permitted to use this button!",
ephemeral: true
})
}
await interaction.guild?.bans.create(user)
await i.update({
content: `Confirmed ban for ${user}\nThey are gone!`,
components: []
})
}
break;
it throws a long error in the entire collector callback saying
No overload matches this call.
Overload 1 of 3, '(event: "end", listener: (collected: Collection<string, ButtonInteraction<CacheType>>, reason: string) => Awaitable<void>): InteractionCollector<...>', gave the following error.
Argument of type '"collect"' is not assignable to parameter of type '"end"'.
Overload 2 of 3, '(event: "dispose" | "collect" | "ignore", listener: (interaction: ButtonInteraction<CacheType>) => Awaitable<void>): InteractionCollector<ButtonInteraction<CacheType>>', gave the following error.
No overload matches this call.
Overload 1 of 3, '(event: "end", listener: (collected: Collection<string, ButtonInteraction<CacheType>>, reason: string) => Awaitable<void>): InteractionCollector<...>', gave the following error.
Argument of type '"collect"' is not assignable to parameter of type '"end"'.
Overload 2 of 3, '(event: "dispose" | "collect" | "ignore", listener: (interaction: ButtonInteraction<CacheType>) => Awaitable<void>): InteractionCollector<ButtonInteraction<CacheType>>', gave the following error.
2 replies
DIAdiscord.js - Imagine an app
Created by Resident Of Prey on 2/2/2024 in #djs-questions
Modal submit problem
look this is my collector, which collects message from a button
const msg = await thread.send({ content: null, embeds: [embed], components: [row] });
message.reply({
content: `created a new thread, <#${thread.id}>`
})

const collector = await msg.createMessageComponentCollector();
collector.on('collect', async (m) => {
const msg = await thread.send({ content: null, embeds: [embed], components: [row] });
message.reply({
content: `created a new thread, <#${thread.id}>`
})

const collector = await msg.createMessageComponentCollector();
collector.on('collect', async (m) => {
and this is the modal inside of the collector:
await m.showModal(modal).catch(console.error);

const modalSubmit = await m.awaitModalSubmit({
filter: async (mm) => mm.user.id === message.author.id && mm.customId == message.id,
time: 1_800_000
});
await m.showModal(modal).catch(console.error);

const modalSubmit = await m.awaitModalSubmit({
filter: async (mm) => mm.user.id === message.author.id && mm.customId == message.id,
time: 1_800_000
});
when i open this modal and click somewhere on the screen, that means to disappear it and execute the modal again, it throws this error
DiscordAPIError[10062]: Unknown interaction
at handleErrors (G:\#BotBackups\BeastCorp\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (G:\#BotBackups\BeastCorp\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (G:\#BotBackups\BeastCorp\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ModalSubmitInteraction.reply (G:\#BotBackups\BeastCorp\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async InteractionCollector.<anonymous> (G:\#BotBackups\BeastCorp\src\prefix-commands\thread.js:115:23) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
DiscordAPIError[10062]: Unknown interaction
at handleErrors (G:\#BotBackups\BeastCorp\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (G:\#BotBackups\BeastCorp\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (G:\#BotBackups\BeastCorp\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ModalSubmitInteraction.reply (G:\#BotBackups\BeastCorp\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async InteractionCollector.<anonymous> (G:\#BotBackups\BeastCorp\src\prefix-commands\thread.js:115:23) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
21 replies