Javascript &引用;无法读取属性';前缀';“未定义”的定义;制造不和机器人时
我想制造一个不和谐的机器人。我已经做了一周了,突然出现了这样一个错误:“无法读取未定义的属性”前缀“。这几个小时来一直把我搞得一团糟。这里是代码(如果它是无用的,有些可能是原因),我感谢所有的帮助,我提前得到。(代码错误在第82-85行)如果您需要任何其他信息,请在discord:StodiusDev#0001上向我发送DMJavascript &引用;无法读取属性';前缀';“未定义”的定义;制造不和机器人时,javascript,discord,discord.js,Javascript,Discord,Discord.js,我想制造一个不和谐的机器人。我已经做了一周了,突然出现了这样一个错误:“无法读取未定义的属性”前缀“。这几个小时来一直把我搞得一团糟。这里是代码(如果它是无用的,有些可能是原因),我感谢所有的帮助,我提前得到。(代码错误在第82-85行)如果您需要任何其他信息,请在discord:StodiusDev#0001上向我发送DM /*eslint不禁用多个空行*/ /*eslint禁用无未使用的变量*/ const Discord=require('Discord.js'); 常数fs=要求('fs
/*eslint不禁用多个空行*/
/*eslint禁用无未使用的变量*/
const Discord=require('Discord.js');
常数fs=要求('fs');
const jsonfile=require('jsonfile');
const client=new Discord.client({
部分:['MESSAGE','CHANNEL','REACTION'],
});
client.commands=new Discord.Collection();
const commandFiles=fs.readdirSync('./commands').filter(file=>file.endsWith('.js'));
const-moderationFiles=fs.readdirSync('./commands/moderation').filter(file=>file.endsWith('.js'));
const funFiles=fs.readdirSync('./commands/fun').filter(file=>file.endsWith('.js'));
const miscsfiles=fs.readdirSync('./commands/miscellanious').filter(file=>file.endsWith('.js'));
常数{
代币
博图时代,
单词数组,
机器人信息,
}=require('./config.json');
client.once('ready',()=>{
log('Bot已准备就绪');
client.user.setActivity(“!help commands”);
});
client.login(令牌);
client.on('guildCreate',guild=>{
统计数据[guild.id]={};
const guildStats=stats[guild.id];
行会数据['serverinfo']={
serverid:guild.id,
前缀:“!”,
};
jsonfile.writeFileSync('stats.json',stats);
行会测试[“适度设置”]={
管理员角色:0,
};
jsonfile.writeFileSync('stats.json',stats);
行会数据['modlogs']={
hasmodlogs:错,
modlogsID:0,
};
jsonfile.writeFileSync('stats.json',stats);
const embed=new Discord.MessageEmbed()
.setTitle('谢谢添加我!')
.setDescription('感谢您添加我!此bot是一个温和而有趣的bot,因此您不需要更多!要获得更多帮助,请说“!help commands`。要添加管理员角色,请说“!setadmin`”。)
.setColor(“蓝色”);
const msgEmbed1=guild.owner.send(嵌入);
guild.systemChannel.send('谢谢邀请我,这里是我所有命令的列表!:wink:'{
嵌入:{
标题:':x:前缀',
颜色:0x2471a3,
description:“所有我的命令的前缀都是\'!\”。要查看更多我的命令,请使用“!help commands”,
字段:[{
姓名:':tada:Fun',
价值:'嗨,丹克拉特,盖拉特,8球,迷因,双关语,滚球,硬币翻转,多格,卡帕,莱尼,lol,美古斯塔,佩佩,三一,蜘蛛侠,匙匠,巨魔,沃特,多兰,不确定,孤独,木偶,凯蒂',
},
{
名称:':繁荣:缓和',
值:“setadmin、ban、kick、modlogss create”,
},
{
名称:':工具:杂项',
值:“帮助命令、ping、invite”,
},
],
页脚:{
文本:“由StodiusDev#0001创建的机器人。”,
},
},
});
});
client.on('message',异步消息=>{
stats[message.guild.id]={};
const guildStats=stats[message.guild.id];
如果(!message.content.startsWith([guildStats].serverinfo.prefix)| message.author.bot)返回;
const args=message.content.slice([guildStats].serverinfo.prefix.length).trim().split(+/);
const commandName=args.shift().toLowerCase();
如果(!client.commands.has(commandName))返回;
const command=client.commands.get(commandName);
如果(!args.length&command.args===true){
const embed=new Discord.MessageEmbed()
.setColor(“#FF0000”)
.setTitle('错误')
.setDescription('参数不足。请说`!help commands`以获取完整的命令列表')
.setFooter('Bot错误日志');
返回消息.channel.send(嵌入);
}
});
for(funFiles的常量文件){
const command=require(`./commands/fun/${file}`);
client.commands.set(command.name,command);
}
for(命令文件的常量文件){
const command=require(`./commands/${file}`);
client.commands.set(command.name,command);
}
for(中庸文件的常量文件){
const command=require(`./commands/moderation/${file}`);
client.commands.set(command.name,command);
}
for(杂项文件的常量文件){
const command=require(`./commands/miscellanious/${file}`);
client.commands.set(command.name,command);
}
putclient.login(令牌)底部的code>和前缀
在所有代码中都需要小写,如这里的标题:':x:prefix',
请看p不是小写[guildStats]
是一个数组,数组没有.serverinfo
属性我想指出.serverinfo来自另一个文件(stats.json),如果你看我在机器人加入帮会时写的顶部,它会正确地写在stats.json文件夹中,但当我尝试获取它时,它会这样说。不管。。。将guildStats
放在[]
中使其成为一个数组,而数组没有名为serverinfo
-。。。你想要的是guildStats.serverinfo.prefix
哦,好吧,我把它改成了guildStats.serverinfo.prefix
,现在它说“无法读取未定义的属性'prefix'”,所以,这是相同的错误-console.log(guildStats)
不,这不是问题,你说的很好,这个问题是一致的80@Stodius你不和谐的名字是什么?Todiusdev#0001刚刚添加的我可以邀请你到服务器上给你看些东西吗
/* eslint-disable no-multiple-empty-lines */
/* eslint-disable no-unused-vars */
const Discord = require('discord.js');
const fs = require('fs');
const jsonfile = require('jsonfile');
const client = new Discord.Client({
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const moderationFiles = fs.readdirSync('./commands/moderation').filter(file => file.endsWith('.js'));
const funFiles = fs.readdirSync('./commands/fun').filter(file => file.endsWith('.js'));
const miscFiles = fs.readdirSync('./commands/miscellanious').filter(file => file.endsWith('.js'));
const {
token,
bot_age,
words_array,
bot_info,
} = require('./config.json');
client.once('ready', () => {
console.log('Bot is ready.');
client.user.setActivity('!help commands');
});
client.login(token);
client.on('guildCreate', guild => {
stats[guild.id] = {};
const guildStats = stats[guild.id];
guildStats['serverinfo'] = {
serverid: guild.id,
prefix: '!',
};
jsonfile.writeFileSync('stats.json', stats);
guildStats['moderationsettings'] = {
adminrole: 0,
};
jsonfile.writeFileSync('stats.json', stats);
guildStats['modlogs'] = {
hasmodlogs: false,
modlogsID: 0,
};
jsonfile.writeFileSync('stats.json', stats);
const embed = new Discord.MessageEmbed()
.setTitle('Thanks for Adding Me!')
.setDescription('Thank you for adding me! This bot is a moderation and fun bot, so you don\'t need any more! For more help, say `!help commands`. To add a admin role, say `!setadmin <roleID>`.')
.setColor('BLUE');
const msgEmbed1 = guild.owner.send(embed);
guild.systemChannel.send('Thanks for inviting me, here are a list of all my commands! :wink:', {
embed: {
title: ':x: Prefix',
color: 0x2471a3,
description: 'The prefix for all my commands is \'!\'. To view more of my commands say `!help commands`',
fields: [{
name: ':tada: Fun',
value: 'hi, dankrate, gayrate, 8ball, meme, pun, roll, coinflip, doge, kappa, lenny, lol, megusta, pepe, sanic, spiderman, spooderman, troll, wat, dolan, notsure, alone, pupper, kitty',
},
{
name: ':boom: Moderation',
value: 'setadmin, ban, kick, modlogss create',
},
{
name: ':tools: Miscellaneous',
value: 'help commands, ping, invite',
},
],
footer: {
text: 'Bot created by StodiusDev#0001.',
},
},
});
});
client.on('message', async message => {
stats[message.guild.id] = {};
const guildStats = stats[message.guild.id];
if (!message.content.startsWith([guildStats].serverinfo.prefix) || message.author.bot) return;
const args = message.content.slice([guildStats].serverinfo.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName);
if (!args.length & command.args === true) {
const embed = new Discord.MessageEmbed()
.setColor('#FF0000')
.setTitle('ERROR')
.setDescription('Not enough arguments. Please say `!help commands` for a full list of commands.')
.setFooter('Bot Error Log');
return message.channel.send(embed);
}
});
for (const file of funFiles) {
const command = require(`./commands/fun/${file}`);
client.commands.set(command.name, command);
}
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
for (const file of moderationFiles) {
const command = require(`./commands/moderation/${file}`);
client.commands.set(command.name, command);
}
for (const file of miscFiles) {
const command = require(`./commands/miscellanious/${file}`);
client.commands.set(command.name, command);
}