这就是我所面临的错误:
/home/ry/node_modules/discord.js/src/client/actions/MessageCreate.js:11
const existing = channel.messages.cache.get(data.id);
^
TypeError: Cannot read properties of undefined (reading 'cache')
at MessageCreateAction.handle (/home/ry/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41)
at Object.module.exports [as MESSAGE_CREATE] (/home/ry/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/ry/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/ry/node_modules/discord.js/src/client/websocket/WebSocketShard.js:435:22)
at WebSocketShard.onMessage (/home/ry/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/ry/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (node:events:527:28)
at Receiver.receiverOnMessage (/home/ry/node_modules/ws/lib/websocket.js:1047:20)
at Receiver.emit (node:events:527:28)
at Receiver.dataMessage (/home/ry/node_modules/ws/lib/receiver.js:517:14)
这是我运行的代码。
const Discord = require('discord.js');
const client = new Discord.Client();
var threads = [
{
channel: '498391317399863307',
//interval: 1000 * 7200,
message: 'hi'
},
{
channel: '498391317399863307',
//interval: 1000 * 7220,
message: 'hello'
},
{
channel: '498391317399863307',
//interval: 1000 * 43200,
message: 'bye'
}
]
client.on('ready', () => {
console.log(Discord.version)
for (i in threads)
{
function a(t, message) {
client.channels.cache.get(t.channel).send(t.message).then(() => {
let x = 1;
if(t.message == "hi") {
x = (Math.random() * ((1000*9000) - (1000*7200))) + 7200000;
console.log("hi: " + (x/1000) + " secs");
} else if (t.message == "hello") {
x = (Math.random() * ((1000*9900) - (1000*25000))) + 9000000;
console.log("\nHello: " + (x/1000) + " secs");
} else if (t.message == "bye") {
x = (Math.random() * ((1000*48600) - (1000*72000))) + 43200000;
console.log("\nBye: " + (x/1000) + " secs");
}
setTimeout(a, x, t)
}).catch(e => {
console.log(e);
})
}
setTimeout(a, threads[i].interval, threads[i])
}
});
client.login('');
本质上,给出的错误与我的代码本身无关。我也尝试过重新安装discord.js,但仍然没有运气。(我使用的是Discord v12)它最初工作,但每次抛出错误,所以停止整个事情。我想知道是否有人知道这个问题的解决方案。谢谢!
编辑:我收到了关于错误来源的评论,因为它显示路径来自node_modules文件夹。我只有一个js文件,这是我发送的代码。我没有创建node_modules文件。
但是,我在这里附加了在node_modules文件夹中找到的MessageCreate.js。
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
class MessageCreateAction extends Action {
handle(data) {
const client = this.client;
const channel = client.channels.cache.get(data.channel_id);
if (channel) {
const existing = channel.messages.cache.get(data.id);
if (existing) return { message: existing };
const message = channel.messages.add(data);
const user = message.author;
let member = message.member;
channel.lastMessageID = data.id;
if (user) {
user.lastMessageID = data.id;
user.lastMessageChannelID = channel.id;
}
if (member) {
member.lastMessageID = data.id;
member.lastMessageChannelID = channel.id;
}
/**
* Emitted whenever a message is created.
* @event Client#message
* @param {Message} message The created message
*/
client.emit(Events.MESSAGE_CREATE, message);
return { message };
}
return {};
}
}
module.exports = MessageCreateAction;
1条答案
按热度按时间jq6vz3qz1#
我的机器人现在收到了相同类型的错误,而它以前工作了很长一段时间。你应该看看你使用的DiscordJS版本。如果它是〈13.3.1,考虑升级- 13.3.1包含了这个问题的修复。