mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(Util): throw an explicit error if a chunk exceeds the max length (#2936)
* fix(Util): throw an explicit error if a chunk exceeds the max length * refactor(Util): consolidate both errors in splitMessage into one * revert(Messages): do not unnecessarily change the error code * revert(Messages): do not remove the word 'the'
This commit is contained in:
@@ -73,7 +73,7 @@ const Messages = {
|
||||
|
||||
TYPING_COUNT: 'Count must be at least 1',
|
||||
|
||||
SPLIT_MAX_LEN: 'Message exceeds the max length and contains no split characters.',
|
||||
SPLIT_MAX_LEN: 'Chunk exceeds the max length and contains no split characters.',
|
||||
|
||||
BAN_RESOLVE_ID: (ban = false) => `Couldn't resolve the user ID to ${ban ? 'ban' : 'unban'}.`,
|
||||
|
||||
@@ -81,8 +81,6 @@ const Messages = {
|
||||
|
||||
SEARCH_CHANNEL_TYPE: 'Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.',
|
||||
|
||||
MESSAGE_SPLIT_MISSING: 'Message exceeds the max length and contains no split characters.',
|
||||
|
||||
GUILD_CHANNEL_RESOLVE: 'Could not resolve channel to a guild channel.',
|
||||
GUILD_VOICE_CHANNEL_RESOLVE: 'Could not resolve channel to a guild voice channel.',
|
||||
GUILD_CHANNEL_ORPHAN: 'Could not find a parent to this guild channel.',
|
||||
|
||||
@@ -56,7 +56,7 @@ class Util {
|
||||
static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) {
|
||||
if (text.length <= maxLength) return text;
|
||||
const splitText = text.split(char);
|
||||
if (splitText.length === 1) throw new RangeError('SPLIT_MAX_LEN');
|
||||
if (splitText.some(chunk => chunk.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
|
||||
const messages = [];
|
||||
let msg = '';
|
||||
for (const chunk of splitText) {
|
||||
|
||||
Reference in New Issue
Block a user