因此,我现在使用的代码给了我一个TypeError:无法为我的ping命令读取undefined的属性'send',然后是TypeError:无法为我的ban命令读取undefined的属性'users',由于我做了什么或忘记了做什么,我还有其他命令不能正常工作,代码一直在工作,直到我向代码添加了权限,然后它就走下坡路了,我不知道在权限之前和之后哪里不工作/它是如何工作的,但后来只是停止工作,我不知道我是否忘记了添加一行或忘记了一行;但我很确定这方面没问题,但我们非常感谢您的帮助。
这是我的主要任务。js
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"]});
//const client = require('discord-buttons');
const fs = require('fs');
require('dotenv').config();
//const prefix = '-';
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.DISCORD_TOKEN);
这是我的命令处理程序
const { Client } = require('discord.js');
const fs = require('fs');
module.exports = (Client, Discord) =>{
const command_files = fs.readdirSync(`./commands/`).filter(file => file.endsWith('.js'));
command.execute(client, message, args, cmd, Discord);
for(const file of command_files){
const command = require(`../commands/${file}`);
if(command.name){
Client.commands.set(command.name, command);
} else {
continue;
}
}
}
这是我的事件处理程序。js
const { Client } = require('discord.js');
const fs = require('fs');
module.exports = (Client, Discord) =>{
const load_dir = (dirs) =>{
const event_files = fs.readdirSync(`./events/${dirs}`).filter(file => file.endsWith('.js'));
for(const file of event_files){
const event = require(`../events/${dirs}/${file}`);
const event_name = file.split('.')[0];
Client.on(event_name, event.bind(null, Discord, Client));
}
}
['client', 'guild'].forEach(e => load_dir(e));
}
这是我的留言。js
const cooldowns = new Map();
module.exports = (Discord, client, message) =>{
const prefix = process.env.PREFIX;
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
if(!command) return;
const validPermissions = [
"CREATE_INSTANT_INVITE",
"KICK_MEMBERS",
"BAN_MEMBERS",
"ADMINISTRATOR",
"MANAGE_CHANNELS",
"MANAGE_GUILD",
"ADD_REACTIONS",
"VIEW_AUDIT_LOG",
"PRIORITY_SPEAKER",
"STREAM",
"VIEW_CHANNEL",
"SEND_MESSAGES",
"SEND_TTS_MESSAGES",
"MANAGE_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY",
"MENTION_EVERYONE",
"USE_EXTERNAL_EMOJIS",
"VIEW_GUILD_INSIGHTS",
"CONNECT",
"SPEAK",
"MUTE_MEMBERS",
"DEAFEN_MEMBERS",
"MOVE_MEMBERS",
"USE_VAD",
"CHANGE_NICKNAME",
"MANAGE_NICKNAMES",
"MANAGE_ROLES",
"MANAGE_WEBHOOKS",
"MANAGE_EMOJIS",
]
if(command.permissions.length){
let invalidPerms = []
for(const perm of command.permissions){
if(!validPermissions.includes(perm)){
return console.log(`Invalid Permissions ${perm}`);
}
if(!message.member.hasPermission(perm)){
invalidPerms.push(perm);
}
}
if (invalidPerms.length){
return message.channel.send(`Missing Permissions: \`${invalidPerms}\``);
}
}
if(!cooldowns.has(command.name)){
cooldowns.set(command.name, new Discord.Collection());
}
const current_time = Date.now();
const time_stamps = cooldowns.get(command.name);
const cooldown_ammount = (command.cooldown) * 1000;
if(time_stamps.has(message.author.id)){
const expiration_time = time_stamps.get(message.author.id) + cooldown_ammount;
if(current_time < expiration_time){
const time_left = (expiration_time - current_time) / 1000;
return message.reply(`Please wait ${time_left.toFixed(1)} more seconds before using ${command.name}`)
}
}
time_stamps.set(message.author.id, current_time);
setTimeout(() => time_stamps.delete(message.author.id), cooldown_ammount);
try{
command.execute(message,args, cmd, client, Discord);
} catch (err){
message.reply("There was an error trying to execute this command!");
console.log(err);
}
}
这是我的ping.js
module.exports = {
name: 'ping',
cooldown: 10,
permissions: ["SEND_MESSAGES"],
description: "this is a ping command!",
execute(client, message, args, cmd, Discord){
message.channel.send('pong!');
}
}
这是我的禁令。js
module.exports = {
name: 'ban',
aliases: ['b'],
permissions: ["ADMINISTRATOR", "BAN_MEMBERS",],
description: "this is a ban command!",
execute(client, message, args, cmd, Discord){
const member = message.mentions.users.first();
if(member){
const memberTarget = message.guild.members.cache.get(member.id);
memberTarget.ban();
message.channel.send('User has been banned');
}else{
message.channel.send('Need to mention a member you wish to ban')
}
}
}
这是一个非常明显的错误,你给出了错误的定义,你做了错误的选择
command.execute(message,args, cmd, client, Discord);
在命令文件中,您使用了
execute(client, message, args, cmd, Discord){
您可以通过在命令处理程序中使用以下内容来解决此问题:
command.execute(client, message, args, cmd, Discord);
希望这有帮助,如果你需要更多的帮助,请在下面评论。
我收到以下JavaScript错误: TypeError:无法读取null的属性“title” 代码如下: mds-iMac: cmscart imac$nodemo app[nodemo] 1.11.0[nodemo]随时重启,输入[nodemo]观看:.[nodemo]启动(node: 2274)DeprecationWarning:在猫鼬中被弃用 [nodemon]应用程序崩溃-正在等待文件
问题内容: 我是ReactJS的新手,遇到一些问题。 我还了解了语法,它说以下代码具有相同的含义。 1。 2。 但是,第一种方法引发此错误 问题答案: YTSearch({key: API_KEY, term: ‘nba’}, function(videos) { this.setState({ videos }); }); 引发错误,因为在此回调内部并未引用函数本身的上下文,因此此处未定义。 在
如果函数在组件中,那么一切都很好。如果我把它单独取出并导出到一个组件中,那么我会得到一个错误TypeError:不能读取未定义的属性(读取'reduce')
TypeError:无法读取应用程序上未定义的属性“collection”。在图层上发布(/home/niko/Desktop/opa/app.js:17:38)。在route的下一个(/home/niko/Desktop/opa/node_modules/express/lib/router/layer.js:95:5)中处理[as handle_request](/home/niko/Desk
问题内容: 当我尝试使用Promise从AngularUI-Bootstrap获取typeahead值时,出现以下错误。 我的HTML标签是: 用我的功能执行以下操作: 我不明白AngularUI- Bootstrap抱怨什么是不确定的。如果我删除最顶部的注释,则这些值会很好显示。中的输出还返回数组中我期望的所有值。 我缺少什么会导致AngularUI-Bootstrap看不到返回的数组? 问题答
TypeError:无法读取未定义的属性(读取“to isoString”)