FS Events Message.js在Discord.js v12中不工作

FS Events Message.js在Discord.js v12中不工作,discord.js,fs,commando,Discord.js,Fs,Commando,我正在尝试将我的事件重做到一个fs事件系统中,以便每个事件都有单独的文件,并且在将代码转换为Discord.JS v12时遇到了一些问题 有人能帮我找出我的message.js文件出了什么问题吗 这是我的密码: index.js const { Client } = require('discord.js-commando'); const path = require('path'); const fs = require('fs'); const server_invite = (proce

我正在尝试将我的事件重做到一个fs事件系统中,以便每个事件都有单独的文件,并且在将代码转换为Discord.JS v12时遇到了一些问题

有人能帮我找出我的
message.js
文件出了什么问题吗

这是我的密码:

index.js

const { Client } = require('discord.js-commando');
const path = require('path');
const fs = require('fs');
const server_invite = (process.env.INVITE_URL);
const owner_id = (process.env.BOT_OWNER);
const prefix = (process.env.BOT_PREFIX);
const stripIndents = require('common-tags').stripIndents;
require('dotenv').config();
const client = new Client({
    commandPrefix: prefix,
    unknownCommandResponse: false,
    disableMentions: 'everyone',
    owner: owner_id,
    invite: server_invite
})

client.registry
    .registerDefaultTypes()
    .registerGroups([
        ['admin', 'Administration'],
        ['mod', 'Moderation'],
        ['fun', 'Fun'],
        ['misc', 'Miscellanious'],
        ['util', 'Utility']

    ])
    .registerDefaultGroups()
    .registerDefaultCommands()
    .registerCommandsIn(path.join(__dirname, 'commands'))


fs.readdir('./events/', (err, files) => {
    if (err) return console.error;
    files.forEach(file => {
        if (!file.endsWith('.js')) return;
        const evt = require(`./events/${file}`);
        let evtName = file.split('.')[0];
        console.log(`Loaded event '${evtName}'`);
        client.on(evtName, evt.bind(null, client));
    });
});

client.on('error', console.error)
client.login(process.env.BOT_TOKEN);
const discord = require("discord.js");
const dotenv = require('dotenv').config;
const prefix = (process.env.BOT_PREFIX);
const fs = require('fs');

module.exports = (client, message) => {
    if (message.author.bot) return;
    if (message.content.indexOf(prefix) !== 0) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    const cmd = client.commands.cache.get(command);
    if (!cmd) return;

    cmd.run(client, message, args);
};
message.js

const { Client } = require('discord.js-commando');
const path = require('path');
const fs = require('fs');
const server_invite = (process.env.INVITE_URL);
const owner_id = (process.env.BOT_OWNER);
const prefix = (process.env.BOT_PREFIX);
const stripIndents = require('common-tags').stripIndents;
require('dotenv').config();
const client = new Client({
    commandPrefix: prefix,
    unknownCommandResponse: false,
    disableMentions: 'everyone',
    owner: owner_id,
    invite: server_invite
})

client.registry
    .registerDefaultTypes()
    .registerGroups([
        ['admin', 'Administration'],
        ['mod', 'Moderation'],
        ['fun', 'Fun'],
        ['misc', 'Miscellanious'],
        ['util', 'Utility']

    ])
    .registerDefaultGroups()
    .registerDefaultCommands()
    .registerCommandsIn(path.join(__dirname, 'commands'))


fs.readdir('./events/', (err, files) => {
    if (err) return console.error;
    files.forEach(file => {
        if (!file.endsWith('.js')) return;
        const evt = require(`./events/${file}`);
        let evtName = file.split('.')[0];
        console.log(`Loaded event '${evtName}'`);
        client.on(evtName, evt.bind(null, client));
    });
});

client.on('error', console.error)
client.login(process.env.BOT_TOKEN);
const discord = require("discord.js");
const dotenv = require('dotenv').config;
const prefix = (process.env.BOT_PREFIX);
const fs = require('fs');

module.exports = (client, message) => {
    if (message.author.bot) return;
    if (message.content.indexOf(prefix) !== 0) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    const cmd = client.commands.cache.get(command);
    if (!cmd) return;

    cmd.run(client, message, args);
};
基本上每次我运行命令时,它都会使机器人崩溃。除此之外,我的
ready.js
事件似乎工作得天衣无缝

下面是my
message.js文件抛出的错误:

/app/events/message.js:13
    const cmd = client.commands.cache.get(command);
                              ^

TypeError: Cannot read property 'cache' of undefined
at module.exports (/app/events/message.js:13:33)
at CommandoClient.emit (events.js:326:22)
at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:125:16)
at WebSocket.emit (events.js:314:20)
at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:797:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yuzuki@1.0.0 start: `node --harmony index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the yuzuki@1.0.0 start script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /app/.npm/_logs/2020-10-07T08_08_09_863Z-debug.log
Process exited with status 1
State changed from up to crashed
我正在用
Discord.JS-commando Discord.JS/commando
节点^12.16.4
运行
Discord.JS^12.0.0

感谢所有回应者的帮助。能够使用提供的响应修复我的
message.js
文件

这是我的工作
message.js
文件,如果有人想使用它:

const client = require('discord.js-commando');
const prefix = (process.env.BOT_PREFIX);
require('dotenv').config;

module.exports = (message) => {

    if (message.author.client) return;
    if (message.content.indexOf(prefix) !== 0) return;


    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    const cmd = client.commands.cache.get(command);
    if (!cmd) return;

    cmd.run(client, message, args);
};

因为您使用的是Commando,所以
消息
事件不需要另一个侦听器。图书馆已经为你做了。删除
message.js
应该会删除错误

发生错误的原因是
client.commands
未定义。您似乎正在使用,这是为不使用突击队的机器人设计的,并且假设您已经使用了。你可能想看一看


请不要在一篇文章中问多个问题。如果您的其他事件处理程序有不同的问题,请。

“它使bot崩溃”发生了什么错误?你能提供完整的错误信息吗?很抱歉反应太晚。我会用它现在给出的错误来更新我的问题。啊,好的。我不知道它不需要这个。