[英]Why is the command handler in discord.js not working?
所以,我正在開發一個 Discord Bot 並想使用命令處理程序,但 for 循環有問題。
Index.js 代碼:
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command)
}
這是命令代碼:
module.export = {
data: {
name: "ban",
description: "Ban an user"
},
async execute(interaction){
//Code
}
}
錯誤告訴我:
client.commands.set(command.data.name, command)
^
TypeError: Cannot read properties of undefined (reading 'name')
at Object.<anonymous> (/Users/yihanzhou/Desktop/LavaBot/index.js:13:38)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
這段代碼有什么問題?
這是因為一個錯誤:
你輸入module.export = {
而不是module.exports = {
這里是 !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.