@sapphire/shapeshift (?) crashes bot when trying to send embed with description exceeding 4096 chars
hi, so I have a message cmd which shows info on a github user in a nice embed. when bot sends the info embed, it also has a button attached to it to help fetch publicly available events for gh user if pressed. I process all interactions on this button through
message.createMessageComponentCollector
method. I do all this inside messageRun
method. The bot send the info embed with button just fine, but when button is pressed to fetch the public events of a github user, it basically crashes bot even when I wrap my whole login inside messageRun in a try-catch block, it still crashes bot because sometimes embed description is set to long string of 4096+ chars which the button interaction would send. The full error I get is here: https://gist.github.com/o-wo/c53217fdcca9d547bba353213a865e4d
I cant figure out what I did wrong, I only want to understand what is crashing the bot: shapeshift or sapphire or its d.js issue? and why it is straight up crashing the bot? even when I put whole code logic inside try catch block. Since error log I see in console mentions shapeshift in many places, it suspects me to believe its causing this? hence I put question mark in post title. apologies for any misunderstanding on my part.
If any experts can point a novice like me in right direction or help me understand its cause, your kindness would be immensely appreciated. 🙏🏽Solution:Jump to solution
Well you correctly identifiet that the error is coming from Shapeshift and the reason is that the string exceeds the maximum length of 4096. What you can do to circumvent this is use the cutText https://www.sapphirejs.dev/docs/Documentation/api-utilities/modules/utilities_src#cuttext method from @sapphire/utilities to ensure it doesn't exceed that length. Use 4096 for the number, or if you have other text in the embed then a lower amount. Discord embeds as a whole cannot exceed 4096 (this is description + title + fields, etc)
That said, I'm surprised this is crashing your entire bot. At best it should land in the
error
listener. Are you sure you haven't implemented a re-throwing mechanism in your own error
or messageError
listener?...3 Replies
Solution
Well you correctly identifiet that the error is coming from Shapeshift and the reason is that the string exceeds the maximum length of 4096. What you can do to circumvent this is use the cutText https://www.sapphirejs.dev/docs/Documentation/api-utilities/modules/utilities_src#cuttext method from @sapphire/utilities to ensure it doesn't exceed that length. Use 4096 for the number, or if you have other text in the embed then a lower amount. Discord embeds as a whole cannot exceed 4096 (this is description + title + fields, etc)
That said, I'm surprised this is crashing your entire bot. At best it should land in the
error
listener. Are you sure you haven't implemented a re-throwing mechanism in your own error
or messageError
listener?that utility function solved my issue so I will mark this as solution, thank you Favna. ❤️
and I dont have any rethrowing mechanism in my code besides what i do in main entry file
index.js
could this be the reason? I doubt it would be since in many last months i have used sapphire+djs and came across many different errors, it never crashed bot. apologies for any inconvenience! nah that's just for login