0

I seem to be getting this error

(node:31844) UnhandledPromiseRejectionWarning: ReferenceError: channel is not defined

I don't understand why this comes up but I know the line of code.

bot.on('message', async (message) => {
    if (message.author.id == bot.user.id) return;
    if(!message.guild) return
    let stickies = await JSON.parse(fs.readFileSync("stickyones.json", "utf8"));

    if(stickies[message.channel.id]) {
        let lastMessage = await channel.messages.fetch(stickies[message.channel.id].lastId);
        lastMessage.delete();
        let newMessage = await message.channel.send(`:warning: __***Sticky Message, Read Before Typing!***__ :warning:\n${stickies[message.channel.id].message}`);

        stickies[message.channel.id] = {
            lastId: newMessage.id,
            message: stickies[message.channel.id].message
        };
        fs.writeFile("stickyones.json", JSON.stringify(stickies), (err) => {
            if (err) console.log(err)
        });
    }
});

It would be this Line right here: let lastMessage = await channel.messages.fetch(stickies[message.channel.id].lastId);

cylence
  • 15
  • 8
  • 4
    where do you define a variable named `channel`? random guess here, but maybe you mean `let lastMessage = await message.channel.messages.fetch .....` – Andrew Lohr Jul 12 '21 at 14:59
  • @AndrewLohr Yeah that was the issue. I assumed channel would have been defined and I couldn't find anything on the matter. Im also pretty new to coding JS so sorry for that! But it did fix it so thanks! :D – cylence Jul 12 '21 at 15:09
  • no problem, keep at it. I'm glad to help out. – Andrew Lohr Jul 12 '21 at 17:51

0 Answers0