首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >关于删除Bot消息的Discord.js错误消息

关于删除Bot消息的Discord.js错误消息
EN

Stack Overflow用户
提问于 2021-03-20 16:58:59
回答 1查看 439关注 0票数 0

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

代码语言:javascript
运行
复制
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
}

下面是命令的代码,它总是遇到以下问题:

代码语言:javascript
运行
复制
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;
        }
    }
}

正如你所看到的,我从来不想编辑我的任何信息,我发送出去的机器人。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-20 18:52:26

你的问题是你删除了这条消息两次。第一次在命令开始时删除它,第二次在case: "patrol"中删除。因此,我建议您只在开关/情况下删除它,因为在default分支中,您希望回复消息。这将是您的代码(我刚刚删除了一行):

代码语言:javascript
运行
复制
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;
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66724224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档