【发布时间】:2022-02-08 14:28:55
【问题描述】:
早安!我目前正在开发一个不和谐的机器人,但我遇到了 事件处理程序 的问题。 “get”命令似乎有问题,但我似乎无法找出问题所在 是,我已将以下代码提供给我的 message.js
module.exports = (Discord, client, msg) => {
const prefix = 'e!';
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command)
if (!cmd){
msg.channel.send("That is not an available command!")
};
if(command) command.execute(client, msg, args, Discord);
};
下面的代码是我的index.js
const Discord = require("discord.js")
const client = new Discord.Client({intents : ["GUILDS", "GUILD_MESSAGES"]});
const button = require('discord-buttons')(client)
const { MessageButton } = require("discord-buttons")
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})
client.login(process.env.token)
任何帮助将不胜感激!
【问题讨论】:
-
这意味着
client.commands是undefined。如果没有看到您的client.commands是什么,我们真的无法提供帮助。 -
我编辑了我的问题并添加了 index.js 文件,希望对您有所帮助
-
我应该在 message.js 中引用
client.commands还是 index.js 文件? -
也许在 index.js 中尝试
module.exports = client或在 message.js 文件中定义client
标签: events discord discord.js typeerror handler