I'd want to upgrade to V13, but I'm still unsure how to loop using forEach in current version.
There's also Util.splitMessage, which will then be removed in the next release.
Is there anybody who can advise or help me in upgrading my script? I'm new to this, Thank you.
my script Discord.js V12:
let chunks = Discord.Util.splitMessage(data);
let embed = new Discord.MessageEmbed().setTitle(`all_players`);
if (chunks.length > 1) {
chunks.forEach((chunk, i) =>
message.channel.send(
embed
.setDescription(chunk)
.setFooter(`Part ${i + 1} / ${chunks.length}`),
),
);
console.log('Completed !all in message');
} else {
msg.channel.send(embed.setDescription(result.length > 0 ? result : 'No Players'));
console.log('Completed !all No Players');
};
Here is a working example of this script.
1....
2....
3....
99....
100....
Part 1/2
101....
102....
103....
199....
200....
Part 2/2
This is the V13 script I'm trying to upgrade, it doesn't work, an error occurs.
let chunks = Discord.Util.splitMessage(data);
if (chunks.length > 1) {
let embed = new Discord.MessageEmbed();
chunks.map((chunk, i) => {
embed.setTitle(`all_players}`)
.setDescription(chunk)
.setFooter(`Part ${i + 1} / ${chunks.length}`)
message.channel.send({ embeds: [embed] })
});
}
error
Error: Expected a string
I found that let chunks = Discord.Util.splitMessage(data); can't work
I have received the answer to this question. My data is an array, just add .splitMessage(data.join("")) or .join("").toString(); Thank you: narze