Reputation: 3
I would like to ask what's wrong with the code, cuz I have no idea about it. It says that toLowerCase is undefined.I've tried many ways to solve this problem, but unfortunately I haven't figured anything out yet. The discord.js version is 11.5.1. Well... there's the code:
const { RichEmbed, Client } = require('discord.js');
const { getMember, formatDate } = require('../../functions.js');
const { stripIndents } = require('common-tags');
module.exports = {
name: 'order',
category: 'server',
description: 'Vytvoří kanál, kde se tě zeptá co za druh objednavky chceš..',
run: async (client, message, args) => {
const member = getMember(message, args.join(' '));
const msg = await message.channel
.send({
embed: {
color: 5729279,
description:
'<a:AsukaLoading:828186024214659102> Pracuje se na požadavku...',
timestamp: new Date(),
footer: {
icon_url: message.author.avatarURL,
text: 'Požadavek od: ' + message.author.username,
},
},
})
.then((m) => m.delete(1999));
if (args[0].toLowerCase() === 'set') {
// ^^
// error here
if (message.content.includes('|')) {
var sluzba = message.content.split('|')[0];
sluzba = sluzba.replace('!order set', '');
var platba = message.content.split('|')[1];
const AsukaOrder3 = new RichEmbed()
.setTitle(
`<:AsukaOrder:835620702559797299> Vaše objednávka byla úspěšně upřesněna!`
)
.addField(
`**<a:AsukaModeration:835266151269138522> Vaše požadavky**`,
stripIndents`**Služba**: ${sluzba}.
**Platba**: ${platba}.`,
true
)
.addBlankField()
.addField(
`<@826756799062474757> By se měli tvé zprávy co v nejbližší době všimnout a pomoct ti s tvou objednávkou!`
)
.setFooter(
'Požadavek od: ' + message.author.username,
message.author.avatarURL
)
.setColor('#576bff')
.setTimestamp();
message.channel.send(AsukaOrder3);
const esayMessage = args.slice(1).join(' ');
message.delete().catch((O_o) => {});
} else {
return;
}
} else {
message.guild
.createChannel(`objednavka-${message.author.id}`, 'text')
.then((c) => {
let everyone = message.guild.roles.find('name', '@everyone');
c.overwritePermissions(everyone, {
SEND_MESSAGES: false,
READ_MESSAGES: false,
});
c.overwritePermissions(message.author, {
SEND_MESSAGES: true,
READ_MESSAGES: true,
});
const AsukaOrder = new RichEmbed()
.setDescription(
`Objednávka uživatele ${message.author.username}, byla úspěšně vytvořena!`
)
.setFooter(
'Požadavek od: ' + message.author.username,
message.author.avatarURL
)
.setColor('#576bff')
.setTimestamp();
message.channel.send(AsukaOrder);
const channel = client.channels.find(
(channel) => channel.name === `objednavka-${message.author.id}`
);
const AsukaOrder2 = new RichEmbed()
.setDescription(
'Předtím než ale začneme, tak budeme potřebovat abyste nám sdělil své požadavky. V první řadě, co za server chcete, čím budete platit, jaké chcete parametry a na jak dlouho u nás chcete hostovat. \n\n Pro upřesnění vašich parametrů stačí napsat: ``!order set (Služba) | (Platební metoda) | (Paramtery) | (Doba trvání)`` \n\n Příklad takovéto objednávky: ``!order set Minecraft | Platební karta | 10GB RAM, 30GB Disk | 30d`` \n\n Vaši objednávku zaregistrujeme nejpozději do pár hodin a pokusíme se ji s vámi dokončit a poskytnout vám naše služby! \n\n V případě nějaké chyby v vytváření objednávky kontaktujte: <@574849327650963469>!'
)
.setTitle(
`<:AsukaOrder:835620702559797299> Vaše objednávka byla úspěšně vytvořena!`
)
.setFooter(
'Požadavek od: ' + message.author.username,
message.author.avatarURL
)
.setColor('#576bff')
.setTimestamp();
channel.send(AsukaOrder2);
if (message.channel.name !== `objednavka-${message.author.id}`)
return message.channel.send({
embed: {
color: 161240,
description: `<a:AsukaError:828188028551299072> Promiň, ale tento příkaz lze použít pouze v kanále s objednávky!`,
timestamp: new Date(),
footer: {
icon_url: message.author.avatarURL,
text: 'Požadavek od: ' + message.author.username,
},
},
});
});
}
},
};
Upvotes: 0
Views: 713
Reputation: 8402
Cannot read x of undefined
This error means that you are trying to access a property off of undefined. For example:
const thisIsUndefined = undefined;
// Uncaught TypeError: Cannot read property 'arbitraryProperty' of undefined
thisIsUndefined.arbitraryProperty;
In your code, it could mean one of two things:
args
is undefined or not an array. Both undefined[0]
and notAnArray[0]
will return undefined (unless you explicitly assign it earlier, like: notAnArray[0] = 'Hello World'
).args
is an array, but there are no elements populating it. [][0]
will return undefined.I find it unlikely that your problem is the former, as it most likely would have thrown an error at args.join(...)
. Assuming it's the latter, the way to fix this would just be to check if args[0]
exists.
// alternatives:
// if (!args.length)
// if (args.length === 0)
if (!args[0]) {
return message.channel.send('I am an error message');
}
Upvotes: 1