mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
feat(Util): allow array for StringOptions' char (#5566)
Co-authored-by: Voltrex <62040526+VoltrexMaster@users.noreply.github.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: Papaia <43409674+papaia@users.noreply.github.com> Co-authored-by: Noel <icrawltogo@gmail.com>
This commit is contained in:
@@ -64,8 +64,20 @@ class Util {
|
||||
static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) {
|
||||
text = Util.verifyString(text, RangeError, 'MESSAGE_CONTENT_TYPE', false);
|
||||
if (text.length <= maxLength) return [text];
|
||||
const splitText = text.split(char);
|
||||
if (splitText.some(chunk => chunk.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
|
||||
let splitText = [text];
|
||||
if (Array.isArray(char)) {
|
||||
while (char.length > 0 && splitText.some(elem => elem.length > maxLength)) {
|
||||
const currentChar = char.shift();
|
||||
if (currentChar instanceof RegExp) {
|
||||
splitText = splitText.map(chunk => chunk.match(currentChar));
|
||||
} else {
|
||||
splitText = splitText.map(chunk => chunk.split(currentChar));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
splitText = text.split(char);
|
||||
}
|
||||
if (splitText.some(elem => elem.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
|
||||
const messages = [];
|
||||
let msg = '';
|
||||
for (const chunk of splitText) {
|
||||
|
||||
Reference in New Issue
Block a user