discord.js - 我在向我的机器人添加新命令时遇到问题,但它有一个类型错误“无法读取未定义的属性‘执行’”
问题描述
我试图向我的机器人添加一个新命令,但我遇到了执行命令时的问题,它在终端中记录了一个错误,无法读取“执行”。这是错误代码:
TypeError: Cannot read property 'execute' of undefined
at Client. < anonymous > (C: \Users\ brand\ scoot.js\ scoot.js: 45: 38)
at Client.emit(node: events: 378: 20)
at MessageCreateAction.handle(C: \Users\ brand\ node_modules\ discord.js\ src\ client\ actions\ MessageCreate.js: 31: 14)
at Object.module.exports[as MESSAGE_CREATE](C: \Users\ brand\ node_modules\ discord.js\ src\ client\ websocket\ handlers\ MESSAGE_CREATE.js: 4: 32)
at WebSocketManager.handlePacket(C: \Users\ brand\ node_modules\ discord.js\ src\ client\ websocket\ WebSocketManager.js: 384: 31)
at WebSocketShard.onPacket(C: \Users\ brand\ node_modules\ discord.js\ src\ client\ websocket\ WebSocketShard.js: 444: 22)
at WebSocketShard.onMessage(C: \Users\ brand\ node_modules\ discord.js\ src\ client\ websocket\ WebSocketShard.js: 301: 10)
at WebSocket.onMessage(C: \Users\ brand\ node_modules\ ws\ lib\ event - target.js: 132: 16)
at WebSocket.emit(node: events: 378: 20)
at Receiver.receiverOnMessage(C: \Users\ brand\ node_modules\ ws\ lib\ websocket.js: 825: 20)
这是我的 index.js
const Discord = require('discord.js');
const client = new Discord.Client();
const fs =require('fs');
client.commands = new Discord.Collection();
const prefix = '!';
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Scoot Is Now Online!');
});
client.on('message', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'help'){
client.commands.get('help').execute(message, args);
}
else if (command == 'fortnitecomp'){
client.commands.get('fortnitecomp').execute(message.args);
}
});
client.login('my token');
这是我的“fortnitecomp”命令模块
module.exports = {
name: 'fortnitecomp',
description: "this command sends a youtube compilation of fortnite (:",
execute(message, args){
message.channel.send('https://www.youtube.com/watch?v=p3gZi62iefo')
}
}
我应该做些什么不同的事情?
解决方案
发现了什么问题!
https://travis-scoot.anti-jew.club/tjNJhq9H
在那个屏幕截图中,底部的代码是工作代码,顶部的代码是错误的代码,我不知道到底发生了什么,但我现在让它工作了!
推荐阅读
- reactjs - Reactjs 从子组件获取状态值
- android - ListView搜索过滤器应用于listview后如何传递意图?
- javascript - 在没有 for 循环 JavaScript 的情况下将数字转换为数组
- android - 当我在 gradle 中使用相同版本的依赖项时出现错误
- r - 输出未显示在 R Markdown PDF 中
- php - 使用 SQL 获取数据
- java - Java - 使用附加的“&”字符检查匹配的括号
- android - 使用 ArrayList 和适配器在 RecyclerView 中加载数据库值
- c# - 测试意外退出时 OmniSharp 抛出错误
- r - 在向量上映射函数