Reputation: 109
it was a silly error ( " } " in the wrong position ), whoever is interested in this handler I upgraded to v13 is very simple but it works well with it.
https://github.com/Inkeee/Tutorial-Discord-Bot
Well, I was trying to learn about slash commands, and in the meantime I did a handler based on some videos, and github, but when executing a slash command the error is thrown x times the number of existing commands. (There are 3 commands, if I use a command the console receives 2 errors)
I suppose the bot is trying to execute all commands, but I don't know exactly what it is, or why!
my code:
const { fs, Discord, erros, colors, emojis, database } = require('../../exports.js');
const slash = [];
const arquivos = fs.readdirSync("./src/slash").filter((file) =>
file.endsWith(".js"))
module.exports = async (client) => {
for (const files of arquivos) {
const file = require(`../../slash/${files}`);
slash.push(file);
client.api.applications(client.user.id).commands.post({data: file.data})
}
client.ws.on('INTERACTION_CREATE', async (i) => {
const command = slash.find(cmd => cmd.data.name === i.data.name.toLowerCase())
if(command) command.execute(client, send, i);
})
async function send(interaction, content) {
return client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: await msg(interaction, content),
},
});
}
async function msg(i, c) {
const m = await Discord.APIMessage.create(client.channels.resolve(i.channel_id), c)
.resolveData()
.resolveFiles();
return { ...m.data, files: m.files }
}
}
module.exports.help = {
name: "ready",
title: "Comandos slashs"
}
the event handlers get normal, the only problem is in the send function, in command
const { Discord, erros, colors, emojis, database, titles} = require('../exports.js');
module.exports = {
data: {
name: "say",
description: "Faça o bot falar",
options: [{
name: "text",
description: "texto que vai na mensagem",
type: 3,
required: true
}]
},
async execute (client, send, i) {
var args = i.data.options
var texto = args.find(args => args.name.toLowerCase() === "text").value;
await send(i, texto)
}
}
Err:
(node:84) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown interaction at RequestHandler.execute (/home/runner /Shinobu/node_modules/discord.js/src/rest/R equestHandler.js:154:13) at processTicksAndRejections (internal/ process/task_queues.js:97:5) at async RequestHandler.push ner/Shinobu/node_modules/discord.js/src/res t/RequestHandler.js:39:14) at Object.execute (/home/runner/S hinobu/src/slash/say.js:20:5) ```
Upvotes: 10
Views: 39445
Reputation: 416
When you are using the slash commands you have 3 seconds to response.
To solve this using the latest discordjs (13.0.1) you can follow these solutions which will give you 15 mins.
Solution 1: Differ the reply and then edit it.
await interaction.deferReply();
const result = await YOUR_FUNCTION();
await interaction.editReply(result);
Solution 2: Reply and then edit it.
await interaction.reply('Working on it');
const result = await YOUR_FUNCTION();
await interaction.editReply(result);
Solution 3: Reply and then response with a follow up.
await interaction.reply('Working on it');
const result = await YOUR_FUNCTION();
await interaction.followUp(result);
You can find more information here!
Upvotes: 38
Reputation: 29
This can be 2 things:
Btw, I can't find anything wrong with your code so you should be good on that front.
Upvotes: 2