Home > Blockchain >  My bot keeps restarting with this error: GUILD_CHANNEL_RESOLVE?
My bot keeps restarting with this error: GUILD_CHANNEL_RESOLVE?

Time:02-16

In the last few days, the bot has always restarted every 24 hours at 01:02 with this error, but today I had the error three times already, and I have no idea how the error occurs, how I can fix it.

This is the Error:

/home/container/node_modules/discord.js/src/structures/Message.js:651
    if (!channel) throw new Error('GUILD_CHANNEL_RESOLVE');
                        ^

Error [GUILD_CHANNEL_RESOLVE]: Could not resolve channel to a guild channel.
    at Message.fetchReference (/home/container/node_modules/discord.js/src/structures/Message.js:651:25)
    at Client.<anonymous> (/home/container/src/events/reply/reply.js:9:45)
    at Client.emit (node:events:532:35)
    at MessageCreateAction.handle (/home/container/node_modules/discord.js/src/client/actions/MessageCreate.js:26:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/container/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/container/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/container/node_modules/ws/lib/event-target.js:199:18)
    at WebSocket.emit (node:events:520:28) {
  [Symbol(code)]: 'GUILD_CHANNEL_RESOLVE'
}

The code where I think the code comes from: I want to use it to check if the message is a reply and if the message that was replied to is from a specific person

const client = require('../../index.js');
const { MessageEmbed } = require('discord.js');
const databese = require('../../database/enabled.json');
const fs = require('fs');

//Log ID: 780479980663603260
//Braxic Reply
client.on('messageCreate', async message => {
    if (message.reference && (await message.fetchReference())?.author.id == '442479859801784320'){
        //Check if the person is allowed to ping
        if(!message.guild) return;
        if(message.author.bot) return;
        const banList = require('../../database/enabled.json').botBanList;
        if(banList.includes(message.author.id)) return;
        //Message in Chat
        message.channel.send(`<@${message.author.id}> Bitte nicht die YouTuber pingen.`)
        message.delete()
    }
})

Maybe someone can help me, or send me a code snippet that fixes the problem

CodePudding user response:

I checked the source code of discord.js (line 612) and the problem is in fetchReference() that will "fetch the message this crosspost/reply/pin-add references, if available to the client". Maybe you are trying to read in a channel not available to you.

CodePudding user response:

Although I am not sure I think there is a problem with your line if (message.reference && (await message.fetchReference())?.author.id == '442479859801784320'). If there is message.fetchReference() it means it is a reply, right? If so you could try the code below. I really dont know if this is going to work but give it a try:

client.on('messageCreate', async message => {
    message.fetchReference().then(msg => 
    if (msg.author.id=='442479859801784320'){
        //Check if the person is allowed to ping
        if(!message.guild) return;
        if(message.author.bot) return;
        const banList = require('../../database/enabled.json').botBanList;
        if(banList.includes(message.author.id)) return;
        //Message in Chat
        message.channel.send(`<@${message.author.id}> Bitte nicht die YouTuber pingen.`)
        message.delete()
    
    }
    )
})
  • Related