noahkaiser
noahkaiser
DIAdiscord.js - Imagine an app
Created by noahkaiser on 11/9/2023 in #djs-questions
DiscordAPIError[10062]: Unknown interaction
async function handleReaction(client, interaction, challenger, opponent, embed, logs) {
try {
const collectorFilter = (reaction, user) => ['👍', '👎'].includes(reaction.emoji.name) && user.id === opponent.user.id;
const reactionCollector = await embed.awaitReactions({ filter: collectorFilter, max: 1, time: 5000, errors: ['time'] });
const reaction = reactionCollector.first();

if (reaction.emoji.name === '👍') {
embed.setFooter({ text: `Challenge #${client.challengeID}` });
embed.setTimestamp();
await challengeEmbed.edit({ embeds: [embed] });
} else if (reaction.emoji.name === '👎') {
await embed.delete({ timeout: 1000 });
await logs.channel.send(`<@${challenger.id}> ${opponent.user.username} rejected your challenge`);
}
} catch (error) {
console.log(interaction);
await interaction.reply("no time left");
throw new Error(error);
}
}

async execute(client, interaction) {
const challenger = interaction.member.user
const opponent = interaction.options.get("opponent")
try {
const match = await createMatchRequest(interaction, challenger, opponent)
await handleReaction(client, interaction, challenger, opponent, match.embed, match.logs)
} catch (error) {
console.log(error)
}
}
async function handleReaction(client, interaction, challenger, opponent, embed, logs) {
try {
const collectorFilter = (reaction, user) => ['👍', '👎'].includes(reaction.emoji.name) && user.id === opponent.user.id;
const reactionCollector = await embed.awaitReactions({ filter: collectorFilter, max: 1, time: 5000, errors: ['time'] });
const reaction = reactionCollector.first();

if (reaction.emoji.name === '👍') {
embed.setFooter({ text: `Challenge #${client.challengeID}` });
embed.setTimestamp();
await challengeEmbed.edit({ embeds: [embed] });
} else if (reaction.emoji.name === '👎') {
await embed.delete({ timeout: 1000 });
await logs.channel.send(`<@${challenger.id}> ${opponent.user.username} rejected your challenge`);
}
} catch (error) {
console.log(interaction);
await interaction.reply("no time left");
throw new Error(error);
}
}

async execute(client, interaction) {
const challenger = interaction.member.user
const opponent = interaction.options.get("opponent")
try {
const match = await createMatchRequest(interaction, challenger, opponent)
await handleReaction(client, interaction, challenger, opponent, match.embed, match.logs)
} catch (error) {
console.log(error)
}
}
- When I wait longer than the reaction time for awaitReactions to reach the catch block of handleReaction - The interaction object is not deferred and replied is false - When trying to reply to the interaction inside of the catch block, I get the discord api error: DiscordAPIError[10062]: Unknown interaction Can someone explain why this error is thrown?
3 replies
DIAdiscord.js - Imagine an app
Created by noahkaiser on 7/23/2023 in #djs-questions
How can I respawn a disconnected client that was not spawned from a ShardingManager?
I've noticed after a long time my web-server will still be running but the bot will be disconnected from discord's gateway. I do not have access to the ShardClientUtil to respawn all shards since the bot was created using the WebSocketManager.
const { Events } = require('discord.js');
module.exports = {
name: Events.ShardDisconnect,
once: false,
async execute(client, event, id) {
console.log(`Shard ${id} disconnected from Discord with code ${event.code}.`);
try {
console.log(await client.ws.shards.get(id))
} catch (error) {
console.error('Error respawning the shard:', error);
}
},
};
const { Events } = require('discord.js');
module.exports = {
name: Events.ShardDisconnect,
once: false,
async execute(client, event, id) {
console.log(`Shard ${id} disconnected from Discord with code ${event.code}.`);
try {
console.log(await client.ws.shards.get(id))
} catch (error) {
console.error('Error respawning the shard:', error);
}
},
};
8 replies