My Discord Bot throws an error when you execute the slash command that the bot is not responding but it still sends the gif afterwards. How could i avoid that problem?
Code:
module.exports = {
data: new SlashCommandBuilder()
.setName('gif')
.setDescription('sends a gif with the given argument')
.addStringOption((option) => option.setName('argument').setDescription('the kind of gif you want').setRequired(true)),
async execute(interaction) {
const param = interaction.options._hoistedOptions[0].value;
await client.search('gifs', {"q": param, "limit": 100})
.then((response) => {
let totalResponses = response.data.length;
let responseIndex = Math.floor(Math.random() * totalResponses);
let gif = response.data[responseIndex];
interaction.channel.send({
files: [gif.images.fixed_height.url]
});
});
}
}
I have literally no idea how to fix this. Maybe the Api Responds too slow and discord thinks its not responding?
Discord Interactions need to be replied to within a certain amount of time or else Discord drops them, using interaction.channel.send
doesn't affect the interaction since you need to use interaction.reply
, that simple switch should solve it.