So basically I am lately always getting the following Error when I delete a message that my Bot sends. The message is not being used by the Bot anymore, but for some reason, it always crashes after deletion.
C:\Users\Admin\Documents\Disc-Bots\discordBot_SGE-EventManager\node_modules\discord.js\src\rest\RequestHandler.js:154
throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Unknown Message
at RequestHandler.execute (C:\Users\Admin\Documents\Disc-Bots\discordBot_SGE-EventManager\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async RequestHandler.push (C:\Users\Admin\Documents\Disc-Bots\discordBot_SGE-EventManager\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async MessageManager.delete (C:\Users\Admin\Documents\Disc-Bots\discordBot_SGE-EventManager\node_modules\discord.js\src\managers\MessageManager.js:126:5) {
method: 'delete',
path: '/channels/822433440103268362/messages/822874032402726952',
code: 10008,
httpStatus: 404
}
Here is the Code for the command where it always has the problems with:
module.exports = {
name: 'hostit',
aliases: ['hostits'],
execute: async function (message, args, client) {
message.delete()
switch(args[0]){
//Patrol Command
case "patrol":
let title = "[SGE] Event - Patrol"
let description = `A new patrol has been hosted by ${message.author}!\nCome down to the patrol and get some activity!\n\nhttps://placeholder.com`
// Notification that it was sent
const confirmationembled = new MessageEmbed()
.setColor('GREEN')
.setDescription('Success! Patrol hosted in <#'+eventChannelId+'>!')
message.channel.send(confirmationembled)
message.delete({ timeout: 5000 })
// Actual event channel
const patrolembed = new MessageEmbed()
patrolembed.setColor('GREEN')
.setTitle(title)
.setDescription(description)
//Log Event Creation
client.channels.cache.get(config.logChannelId).send("[**<@"+message.author+">**] hosted a patrol at "+new Date().toLocaleString())
// Send Event to Eventchannel
const channel = message.guild.channels.cache.get(config.eventChannelId)
if (!channel) {
const { owner } = await client.fetchApplication()
return owner.send("Channel does not exist, please check your config.json file.")
}
channel.send(patrolembed)
channel.send('NoGhostPing!').then(msg => msg.delete())
break;
// Not an host command
default:
message.reply("This Command does not exists, please use -help to see all commands!").then(msg => { msg.delete({ timeout: 5000 })})
break;
}
}
}
As you see I never actually want to edit any of my messages, that I send out with the bot.
Your problem is that you delete the message twice. The first time you delete it right at the start of the command, the second time in the case: "patrol"
. So I would recommend you to only delete it in the switch/case, because in the default
branch you want to reply to the message. This will be your code then (I just removed one line):
module.exports = {
name: 'hostit',
aliases: ['hostits'],
execute: async function (message, args, client) {
switch(args[0]){
//Patrol Command
case "patrol":
let title = "[SGE] Event - Patrol"
let description = `A new patrol has been hosted by ${message.author}!\nCome down to the patrol and get some activity!\n\nhttps://placeholder.com`
// Notification that it was sent
const confirmationembled = new MessageEmbed()
.setColor('GREEN')
.setDescription('Success! Patrol hosted in <#'+eventChannelId+'>!')
message.channel.send(confirmationembled)
message.delete({ timeout: 5000 })
// Actual event channel
const patrolembed = new MessageEmbed()
patrolembed.setColor('GREEN')
.setTitle(title)
.setDescription(description)
//Log Event Creation
client.channels.cache.get(config.logChannelId).send("[**<@"+message.author+">**] hosted a patrol at "+new Date().toLocaleString())
// Send Event to Eventchannel
const channel = message.guild.channels.cache.get(config.eventChannelId)
if (!channel) {
const { owner } = await client.fetchApplication()
return owner.send("Channel does not exist, please check your config.json file.")
}
channel.send(patrolembed)
channel.send('NoGhostPing!').then(msg => msg.delete())
break;
// Not an host command
default:
message.reply("This Command does not exists, please use -help to see all commands!").then(msg => { msg.delete({ timeout: 5000 })})
break;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.