mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat: Util.splitMessage always return an array (#3035)
* Making Util.splitMessage always return an array Util.splitMessage sometimes returns an array, but other times it returns a string. This should make it so that it always returns an array. * jsdoc Co-Authored-By: TNThacker2015 <37024464+TNThacker2015@users.noreply.github.com> * docs(Util): remove superfluous space in docstring
This commit is contained in:
@@ -53,11 +53,11 @@ class Util {
|
|||||||
* Splits a string into multiple chunks at a designated character that do not exceed a specific length.
|
* Splits a string into multiple chunks at a designated character that do not exceed a specific length.
|
||||||
* @param {StringResolvable} text Content to split
|
* @param {StringResolvable} text Content to split
|
||||||
* @param {SplitOptions} [options] Options controlling the behavior of the split
|
* @param {SplitOptions} [options] Options controlling the behavior of the split
|
||||||
* @returns {string|string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) {
|
static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) {
|
||||||
text = this.resolveString(text);
|
text = this.resolveString(text);
|
||||||
if (text.length <= maxLength) return text;
|
if (text.length <= maxLength) return [text];
|
||||||
const splitText = text.split(char);
|
const splitText = text.split(char);
|
||||||
if (splitText.some(chunk => chunk.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
|
if (splitText.some(chunk => chunk.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
|
||||||
const messages = [];
|
const messages = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user