删除 Bot 消息时出现 Discord.js 错误消息

时间:2021-03-20 16:58:59

标签: javascript discord discord.js

所以基本上,当我删除我的 Bot 发送的消息时,我最近总是收到以下错误。该消息不再被机器人使用,但由于某种原因,它总是在删除后崩溃。

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
}

这是命令的代码,它总是有问题:

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;
        }
    }
}

如您所见,我实际上从未想要编辑我与机器人一起发送的任何消息。

1 个答案:

答案 0 :(得分:1)

您的问题是您删除了两次邮件。第一次在命令开始时删除它,第二次在 case: "patrol" 中删除它。所以我建议你只在 switch/case 中删除它,因为在 default 分支中你想回复消息。这将是您的代码(我刚刚删除了一行):

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;
        }
    }
}