A: Discord.js v12+ 通道未定义

A: Discord.js v12+ channel is not defined

我似乎遇到了这个错误

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

我不明白为什么会出现这种情况,但我知道这行代码。

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

这里就是这条线:let lastMessage = await channel.messages.fetch(stickies[message.channel.id].lastId);

你在哪里定义一个名为channel的变量?在这里随机猜测,但也许你的意思是让 lastMessage = await message.channel.messages.fetch