My Hive Posts

    Fix Issue with Help Command in Community-Discord-BOT

    Repository

    https://github.com/discord-bot-tutorial/Community-Discord-BOT Pull Request : https://github.com/discord-bot-tutorial/Community-Discord-BOT/pull/130

    Project Info

    A community-driven public Discord-BOT using C# and Discord .NET. The goal of this project is to create a solid general-purpose bot that can be easily extended and used in new and interesting ways.

    Bug Fixes

    Issue?

    The help command of the bot was not checking the size of the embed. When the size reaches 6000 characters an exception is thrown and no help is sent as shown below https://github.com/discord-bot-tutorial/Community-Discord-BOT/issues/81

    Solution?

    After checking the code, all the help messages is adding as an Embed Field and when we are building the message the length of the message is going over 6000. At first I have taken a deep copy of the Embed Fields

    var fields = builder.Fields.ToList();

    Now checking if the embed length is over 6000. If it is more than 6000 removing the initial 10 fields from the embed. After removing fields again checking the length, if it is more just decreasing the initial count by 1 so that this time I will take one less than the previous one.

    So when I am sending the message I am sending it for the first 10 fields only and the next message is sent for the remaining field.

    GitHub Account

    https://github.com/codingdefined