Reputation:
I'm currently trying to make a purge command right now (following reconlx's Purge Command tutorial for DJS v13), and I keep receiving a DiscordAPI
Error.
The command only works once, however, it doesn't reply with embeds like it's supposed to, then crashes along with every other command there is. It does become functional again after a certain period of time then the cycle repeats over and over again.
I have made sure that I had the right intents (which I do) and such, but nothing seems to work... I have no idea what in the world is causing the error. Anyone who would be willing to help is doing me a favour.
Oh, and here's the code for purge.js and the error in question down below.
const { MessageEmbed } = require("discord.js");
const ms = require("ms");
module.exports = {
name: "purge",
description: "Purges messages",
userPermissions: ["MANAGE_MESSAGES"],
options: [
{
name: "amount",
description: "Amount of messages to purge",
type: "INTEGER",
required: true,
},
],
run: async (client, interaction) => {
const amount = interaction.options.getInteger("amount");
const limitEmbed = new MessageEmbed()
.setColor("#2F3136")
.setTitle("You may only purge 100 messages at a time!")
.setFooter({ text: "Error: Limit Reached" })
if (amount > 100)
return interaction.followUp({
embeds:
[limitEmbed],
});
const messages = await interaction.channel.messages.fetch({
limit: amount + 1,
});
const filtered = messages.filter(
(msg) => Date.now() - msg.createdTimestamp < ms("14 days")
);
await interaction.channel.bulkDelete(filtered)
const successEmbed = new MessageEmbed()
.setColor("#2F3136")
.setTitle(`Successfully purged ${filtered.size - 1} messages!`)
.setFooter({ text: "Action Successfully Performed" })
interaction.followUp({
embeds:
[successEmbed],
});
},
};
Error:
DiscordAPIError: Unknown Message
at RequestHandler.execute (C:\Users\admin\Desktop\Tonkotsu\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (C:\Users\admin\Desktop\Tonkotsu\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async InteractionWebhook.send (C:\Users\admin\Desktop\Tonkotsu\node_modules\discord.js\src\structures\Webhook.js:196:15) {
method: 'post',
path: '/webhooks/950050048618688572/aW50ZXJhY3Rpb246OTk5MjYyNTIyMTc3NzQ5MDAzOmhGaUJVQkF6YjduVUlZNTJsT1MwV254T2FYdEJiaUNMWDdwUWloYzhyNnJudERLMHhxak96RTlkTmpDQW5sdEhONnhKSGkyZkdlQndmWGJQSFM0dk52bGduZ3hBTlE3S3g4R2JBRWFRdDNEbmtrb3Z6a0hpVk8yU2hIYllyemhm?wait=true',
code: 10008,
httpStatus: 404,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: 'Successfully purged 3 messages!',
type: 'rich',
description: null,
url: null,
timestamp: 0,
color: 3092790,
fields: [],
thumbnail: null,
image: null,
author: null,
footer: {
text: 'Action Successfully Performed',
icon_url: undefined
}
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
Upvotes: 0
Views: 5346
Reputation: 1362
You should use interaction.reply(...)
instead of interaction.followUp(...)
, followUp
is used when you already replied to a message and want to continue replying to the interaction. So it will throw an error if you trying to use it on an interaction who hasn't been replied yet.
Upvotes: 1