【问题标题】:Discord.js error message on deleting Bot messageDiscord.js 删除 Bot 消息时出现错误消息
【发布时间】:2021-06-17 19:25:50
【问题描述】:

所以基本上我最近在删除我的机器人发送的消息时总是收到以下错误。该消息不再被 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;
        }
    }
}

如您所见,我实际上从不想编辑我使用机器人发送的任何消息。

【问题讨论】:

  • 你能添加你的代码吗?
  • 你应该发布你的代码,查看how to ask

标签: javascript discord discord.js


【解决方案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;
        }
    }
}

【讨论】:

  • 啊,我怎么没看到。非常感谢!
猜你喜欢
  • 2022-09-28
  • 2021-01-28
  • 2016-11-17
  • 2020-02-10
  • 1970-01-01
  • 1970-01-01
  • 2018-08-26
  • 2020-07-04
  • 1970-01-01
相关资源
最近更新 更多