I'm trying to make a script that converts chars from my file and converts them into dices, but the problem is that the script puts an error every time when 'k' for loop is longer than 3 then msg.reply() cannot process it and drops an error. Script here:
const fs = require('fs')
const path = require("path");
const { EmbedBuilder } = require('discord.js')
exports.run = (bot, msg, args) => {
var litery = 'ABCDEFGHIJKLMNOPQRSTUVWXYZÄËÏÖÜÅÆŒØ12345⨀ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ67890↑↓←→'//40
var dice = [
'<:Oginiowa:1019968984646439013>',
'<:Elektryczna:1019968982930968696>',
'<:Wiatrowa:1019968981349711973>',
'<:Zatruta:1019968979760054302>',
'<:Lodowa:1019968978292047872>',
'<:Hazardowa:1019968972889788438>',
'<:Zepsuta:1019968975129550928>',
'<:Zelazna:1019968976941498418>',
'<:Sejfowa:1019968986391269457>',
'<:Minowa:1019981938775298068>',
'<:Jasna:1019981936501997608>',
'<:Cierna:1019981934601973830>',
'<:Uszkodzona:1019981933066850314>',
'<:Critical:1019981931401715722>',
'<:Energy:1019981929409413131>',
'<:Poswiecenie:1019981946127929406>',
'<:Strzala:1019981944261464186>',
'<:LosowyWzrost:1019981942499844187>',
'<:Procna:1019981940700479668>',
'<:Death:1020026235910377503>',
'<:Teleport:1020026233486061618>',
'<:Laser:1020026229946065069>',
'<:Mimic:1020026227404316773>',
'<:Infect:1020026224648658944>',
'<:ModifiedElectric:1020026222098518106>',
'<:Absorb:1020026219498049536>',
'<:MightyWind:1020026216301989888>',
'<:Switch:1020026213252739092',
'<:Gear:1020026210786496633>',
'<:Wave:1020026207426838669>',
'<:Flame:1020026204532789330>',
'<:Uleczajaca:1020026202133626930>',
'<:Klonowa:1020026199264739429>',
'<:UszkodzonyWzrost:1020026196681052322>',
'<:Hojna:1020026194067996753>',
'<:Kamien:1020026191878570034>',
'<:Szybkostrzalowa:1020026189533958274>',
'<:Berserkerowa:1020026187445178439>',
'<:Sniezkowa:1020026185159282768>',
'<:Whim:1020026241790779413>',
'<:Pinball:1020026238678609961>',
'<:Nuclear:1020402792311050400>',
'<:Landmine:1020402795888791646>',
'<:SandSwamp:1020402798409555968>',
'<:Joker:1020402800234090496>',
'<:HolySword:1020402802129899570>',
'<:Hell:1020402803941843135>',
'<:Shield:1020402805934133338>',
'<:Blizzard:1020402807913857055>',
'<:Growth:1020402810115866704>',
'<:Summoner:1020402812364017735>',
'<:Solar:1020402814733783050>',
'<:Assassin:1020402816898039888>',
'<:Atomic:1020402819372691607>',
'<:Gun:1020402821922824262>',
'<:Typhoon:1020402825802567881>',
'<:Supplement:1020402827455119470>',
'<:Metastasis:1020402823919317012>',
'<:Time:1020402829766168668>',
'<:Combo:1020402830890246146>',
'<:Lunar:1020402833780121712>',
'<:Flow:1020402836338655252>',
'<:Star:1020402839132061757>',
'<:ix10:1020402768776810517>',
'<:Silence:1020402767459786752>',
'<:Royal:1020402770785869995>',
'<:YinYang:1020402772702662816>',
'<:Scope:1020402775311519944>',
'<:Bubble:1020402777157009519>',
'<:Guardian:1020402778834743450>',
'<:Overheat:1020402780617314354>',
'<:Earthquake:1020402782970323004>',
'<:Timewinder:1020402784874545182>',
'<:Recharge:1020402786531295252>',
'<:Compression:1020402788464857119>',
'<:LightningCloud:1020402790398443570>'
];
var ln = dice.length
if(args[0] === 'deck') {
if (args[1] === 'random') {
var sel;
var send;
var used = [];
for(var i = 0; i < 5; i++) {
sel = dice[Math.floor(Math.random() * ln)]
if(used.includes(sel)) {
i = i - 1
continue;
}
if (i == 0) { send = sel + ' ' }
else if (i == 4) { send = send + sel }
else { send = send + sel + ' ' }
used.push(sel)
}
msg.reply(send)
} else if (!Number.isNaN(+args[1])) {
let decks = fs.readFileSync(path.resolve(__dirname, '..\\decks.c'), 'utf-8');
let perdeck = decks.split('\r\n')
let ln = perdeck.length
if(args[1] < 1 || args[1] > ln) {
msg.reply('That deck doesn\'t exist')
console.log(ln)
} else {
let seg = perdeck[args[1]-1].split(' ')
if (seg[0] === 'CO-OP') {
let dicesend = ' ';
let dicesend2 = ' ';
for(var j = 1; j < 6; j++) {
/*if(!dicesend) { var dicesend = dice[litery.indexOf(litery.charAt(k))] }
else { var dicesend = dicesend + dice[litery.indexOf(litery.charAt(k))] }*/
if(dicesend === ' ') { dicesend = dice[litery.indexOf(seg[2].charAt(j-1))] }
else { dicesend = dicesend + dice[litery.indexOf(seg[2].charAt(j-1))] }
}
for(var k = 1; k < 3; k++) {
/*if(!dicesend) { var dicesend = dice[litery.indexOf(litery.charAt(k))] }
else { var dicesend = dicesend + dice[litery.indexOf(litery.charAt(k))] }*/
if(dicesend2 === ' ') { dicesend2 = dice[litery.indexOf(seg[3].charAt(k-1))] }
else { dicesend2 = dicesend2 + dice[litery.indexOf(seg[3].charAt(k-1))] }
}
const embed = new EmbedBuilder()
embed.setTitle(seg[5])
embed.setDescription(`Type: ${seg[0]}`)
embed.addFields({ name: `Main: ${dicesend}\nSupport: ${dicesend2}`, value: seg[4] })
embed.setColor(seg[1])
msg.reply({embeds: [embed]})
console.log(dicesend)
console.log(dicesend2)
} else {
const embed = new EmbedBuilder()
embed.setTitle(seg[4])
embed.setDescription(`Type: ${seg[0]}`)
embed.addFields({ name: seg[2], value: seg[3] })
embed.setColor(seg[1])
msg.reply({embeds: [embed]})
}
}
} else {
msg.reply('This subcommand doesn\'t exist')
}
}
}
And the error:
C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:76
throw this.error;
^
CombinedPropertyError: Received one or more errors
at ArrayValidator.handle (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:463:70)
at ArrayValidator.parse (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:142:88)
at EmbedBuilder.addFields (C:\Users\Tomek\Music\DiscordBot\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:17:42)
at exports.run (C:\Users\Tomek\Music\DiscordBot\modules\randomdice.js:130:31)
at Client.<anonymous> (C:\Users\Tomek\Music\DiscordBot\main.js:91:21)
at Client.emit (node:events:525:35)
at MessageCreateAction.handle (C:\Users\Tomek\Music\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
at module.exports [as MESSAGE_CREATE] (C:\Users\Tomek\Music\DiscordBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Tomek\Music\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\Tomek\Music\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22) {
errors: [
[
0,
CombinedPropertyError: Received one or more errors
at ObjectValidator.handleIgnoreStrategy (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:1223:72)
at ObjectValidator.handleStrategy (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:1102:47)
at ObjectValidator.handle (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:1193:17)
at ObjectValidator.run (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:128:23)
at ArrayValidator.handle (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:457:37)
at ArrayValidator.parse (C:\Users\Tomek\Music\DiscordBot\node_modules\@sapphire\shapeshift\dist\index.js:142:88)
at EmbedBuilder.addFields (C:\Users\Tomek\Music\DiscordBot\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:17:42)
at exports.run (C:\Users\Tomek\Music\DiscordBot\modules\randomdice.js:130:31)
at Client.<anonymous> (C:\Users\Tomek\Music\DiscordBot\main.js:91:21)
at Client.emit (node:events:525:35) {
errors: [ [ 'name', [ExpectedConstraintError] ] ]
}
]
]
}
Node.js v18.8.0
If i don't know a simple thing then sorry, I'm a newbie that knows how to code but may not know certain things, Thanks for any help!