Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

c# - Message content is too long, length must be less or equal to 2000

whenever i do !fortnite pc Ninja it works just fine but if i did !fortnite pc geo.java it would give me that error. i have tried quite a bit of ways to fix this and none of them have worked. I even tried other names and they worked. I think it is the "." in the name but i dont know how i would fix this.. any help would be nice thanks. here is the code:

[Command("fortnite")]
    public async Task fortnite(string type, [Remainder]string name)
    {
        using (var client = new FortniteClient("aec756fb-d0ac-4808-a1e1-9be7c421ebcc"))
        {
            try
            {
                if (type == "pc" || type == "Pc")
                {
                    var response = await client.FindPlayerAsync(Platform.Pc, Convert.ToString(name));
                    //solo
                    var solokills = response.Stats[Playlist.Solo][Stat.Kills].ValueInt;
                    var soloscore = response.Stats[Playlist.Solo][Stat.Score].ValueInt;
                    var solospm = response.Stats[Playlist.Solo][Stat.ScorePerMatch].ValueDec;
                    var solokd = response.Stats[Playlist.Solo][Stat.KillDeathRatio].ValueDec;
                    var solomatches = response.Stats[Playlist.Solo][Stat.Matches].ValueInt;
                    var solowr = response.Stats[Playlist.Solo][Stat.WinRatio].ValueDec;
                    var solokpm = response.Stats[Playlist.Solo][Stat.KillsPerMatch].ValueDec;
                    var solotrnrating = response.Stats[Playlist.Solo][Stat.TrnRating].Value;

                    var pcsolo = Helpers.CreateEmbed(Context, "**Solo**

Score: " + soloscore + "
Score Per Match: " + solospm + "
K/D: " + solokd + "
W/R: " + solowr + "
Matches: " + solomatches + "
Kills: " + solokills + "
Kills Per Match: " + solokpm + "
TRN Rating: " + solotrnrating);
                    pcsolo.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, pcsolo);
                    //duo
                    //    await ReplyAsync("", false, pcsolo);

                    var duokills = response.Stats[Playlist.Duo][Stat.Kills].ValueInt;
                    var duoscore = response.Stats[Playlist.Duo][Stat.Score].ValueInt;
                    var duospm = response.Stats[Playlist.Duo][Stat.ScorePerMatch].ValueDec;
                    var duokd = response.Stats[Playlist.Duo][Stat.KillDeathRatio].ValueDec;
                    var duomatches = response.Stats[Playlist.Duo][Stat.Matches].ValueInt;
                    var duowr = response.Stats[Playlist.Duo][Stat.WinRatio].ValueDec;
                    var duokpm = response.Stats[Playlist.Duo][Stat.KillsPerMatch].ValueDec;
                    var duotrnrating = response.Stats[Playlist.Duo][Stat.TrnRating].Value;

                    var pcduo = Helpers.CreateEmbed(Context, "**Duo**

Score: " + duoscore + "
Score Per Match: " + duospm + "
K/D: " + duokd + "
W/R: " + duowr + "
Matches: " + duomatches + "
Kills: " + duokills + "
Kills Per Match: " + duokpm + "
TRN Rating: " + duotrnrating);
                    pcduo.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, pcduo);
                    //squad
                    var Squadkills = response.Stats[Playlist.Squad][Stat.Kills].ValueInt;
                    var Squadscore = response.Stats[Playlist.Squad][Stat.Score].ValueInt;
                    var Squadspm = response.Stats[Playlist.Squad][Stat.ScorePerMatch].ValueDec;
                    var Squadkd = response.Stats[Playlist.Squad][Stat.KillDeathRatio].ValueDec;
                    var Squadmatches = response.Stats[Playlist.Squad][Stat.Matches].ValueInt;
                    var Squadwr = response.Stats[Playlist.Squad][Stat.WinRatio].ValueDec;
                    var Squadkpm = response.Stats[Playlist.Squad][Stat.KillsPerMatch].ValueDec;
                    var Squadtrnrating = response.Stats[Playlist.Squad][Stat.TrnRating].Value;

                    var pcSquad = Helpers.CreateEmbed(Context, "**Squad**

Score: " + Squadscore + "
Score Per Match: " + Squadspm + "
K/D: " + Squadkd + "
W/R: " + Squadwr + "
Matches: " + Squadmatches + "
Kills: " + Squadkills + "
Kills Per Match: " + Squadkpm + "
TRN Rating: " + Squadtrnrating);
                    pcSquad.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, pcSquad);
                    // await ReplyAsync("", false, pcSquad);
                }
                else if (type == "psn" || type == "Psn")
                {
                    var response = await client.FindPlayerAsync(Platform.Psn, name);
                    //solo
                    var solokills = response.Stats[Playlist.Solo][Stat.Kills].ValueInt;
                    var soloscore = response.Stats[Playlist.Solo][Stat.Score].ValueInt;
                    var solospm = response.Stats[Playlist.Solo][Stat.ScorePerMatch].ValueDec;
                    var solokd = response.Stats[Playlist.Solo][Stat.KillDeathRatio].ValueDec;
                    var solomatches = response.Stats[Playlist.Solo][Stat.Matches].ValueInt;
                    var solowr = response.Stats[Playlist.Solo][Stat.WinRatio].ValueDec;
                    var solokpm = response.Stats[Playlist.Solo][Stat.KillsPerMatch].ValueDec;
                    var solotrnrating = response.Stats[Playlist.Solo][Stat.TrnRating].Value;

                    var psnsolo = Helpers.CreateEmbed(Context, "**Solo**

Score: " + soloscore + "
Score Per Match: " + solospm + "
K/D: " + solokd + "
W/R: " + solowr + "
Matches: " + solomatches + "
Kills: " + solokills + "
Kills Per Match: " + solokpm + "
TRN Rating: " + solotrnrating);
                    psnsolo.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, psnsolo);
                    //duo

                    var duokills = response.Stats[Playlist.Duo][Stat.Kills].ValueInt;
                    var duoscore = response.Stats[Playlist.Duo][Stat.Score].ValueInt;
                    var duospm = response.Stats[Playlist.Duo][Stat.ScorePerMatch].ValueDec;
                    var duokd = response.Stats[Playlist.Duo][Stat.KillDeathRatio].ValueDec;
                    var duomatches = response.Stats[Playlist.Duo][Stat.Matches].ValueInt;
                    var duowr = response.Stats[Playlist.Duo][Stat.WinRatio].ValueDec;
                    var duokpm = response.Stats[Playlist.Duo][Stat.KillsPerMatch].ValueDec;
                    var duotrnrating = response.Stats[Playlist.Duo][Stat.TrnRating].Value;

                    var psnduo = Helpers.CreateEmbed(Context, "**Duo**

Score: " + duoscore + "
Score Per Match: " + duospm + "
K/D: " + duokd + "
W/R: " + duowr + "
Matches: " + duomatches + "
Kills: " + duokills + "
Kills Per Match: " + duokpm + "
TRN Rating: " + duotrnrating);
                    psnduo.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, psnduo);
                    //squad
                    var Squadkills = response.Stats[Playlist.Squad][Stat.Kills].ValueInt;
                    var Squadscore = response.Stats[Playlist.Squad][Stat.Score].ValueInt;
                    var Squadspm = response.Stats[Playlist.Squad][Stat.ScorePerMatch].ValueDec;
                    var Squadkd = response.Stats[Playlist.Squad][Stat.KillDeathRatio].ValueDec;
                    var Squadmatches = response.Stats[Playlist.Squad][Stat.Matches].ValueInt;
                    var Squadwr = response.Stats[Playlist.Squad][Stat.WinRatio].ValueDec;
                    var Squadkpm = response.Stats[Playlist.Squad][Stat.KillsPerMatch].ValueDec;
                    var Squadtrnrating = response.Stats[Playlist.Squad][Stat.TrnRating].Value;

                    var psnSquad = Helpers.CreateEmbed(Context, "**Squad**

Score: " + Squadscore + "
Score Per Match: " + Squadspm + "
K/D: " + Squadkd + "
W/R: " + Squadwr + "
Matches: " + Squadmatches + "
Kills: " + Squadkills + "
Kills Per Match: " + Squadkpm + "
TRN Rating: " + Squadtrnrating);
                    psnSquad.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, psnSquad);

                }
                else if (type == "xbl" || type == "Xbl")
                {
                    var response = await client.FindPlayerAsync(Platform.Xbl, name);
                    //solo
                    var solokills = response.Stats[Playlist.Solo][Stat.Kills].ValueInt;
                    var soloscore = response.Stats[Playlist.Solo][Stat.Score].ValueInt;
                    var solospm = response.Stats[Playlist.Solo][Stat.ScorePerMatch].ValueDec;
                    var solokd = response.Stats[Playlist.Solo][Stat.KillDeathRatio].ValueDec;
                    var solomatches = response.Stats[Playlist.Solo][Stat.Matches].ValueInt;
                    var solowr = response.Stats[Playlist.Solo][Stat.WinRatio].ValueDec;
                    var solokpm = response.Stats[Playlist.Solo][Stat.KillsPerMatch].ValueDec;
                    var solotrnrating = response.Stats[Playlist.Solo][Stat.TrnRating].Value;

                    var xblsolo = Helpers.CreateEmbed(Context, "**Solo**

Score: " + soloscore + "
Score Per Match: " + solospm + "
K/D: " + solokd + "
W/R: " + solowr + "
Matches: " + solomatches + "
Kills: " + solokills + "
Kills Per Match: " + solokpm + "
TRN Rating: " + solotrnrating);
                    xblsolo.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, xblsolo);
                    //duo
                    var duokills = response.Stats[Playlist.Duo][Stat.Kills].ValueInt;
                    var duoscore = response.Stats[Playlist.Duo][Stat.Score].ValueInt;
                    var duospm = response.Stats[Playlist.Duo][Stat.ScorePerMatch].ValueDec;
                    var duokd = response.Stats[Playlist.Duo][Stat.KillDeathRatio].ValueDec;
                    var duomatches = response.Stats[Playlist.Duo][Stat.Matches].ValueInt;
                    var duowr = response.Stats[Playlist.Duo][Stat.WinRatio].ValueDec;
                    var duokpm = response.Stats[Playlist.Duo][Stat.KillsPerMatch].ValueDec;
                    var duotrnrating = response.Stats[Playlist.Duo][Stat.TrnRating].Value;

                    var xblduo = Helpers.CreateEmbed(Context, "**Duo**

Score: " + duoscore + "
Score Per Match: " + duospm + "
K/D: " + duokd + "
W/R: " + duowr + "
Matches: " + duomatches + "
Kills: " + duokills + "
Kills Per Match: " + duokpm + "
TRN Rating: " + duotrnrating);
                    xblduo.WithThumbnailUrl("https://png.icons8.com/color/1600/fortnite.png");
                    await Helpers.SendMessage(Context, xblduo);
                    //squad
                    var Squadkills = response.Stats[Playlist.Squad][Stat.Kills].ValueInt;
                    var Squadscore = response.Stats[Playlist.Squad][Stat.Score].ValueInt;
                    var Squadspm = response.Stats[Playlist.Squad][Stat.ScorePerMatch].ValueDec;
                    var Squadkd = response.Stats[Playlist.Squad][Stat.KillDeathRatio].ValueDec;
                    var Squadmatches = response.Stats[Playlist.Squad][Stat.Matches].ValueInt;
                    var Squadwr = response.Stats[Playlist.Squad][Stat.WinRatio].ValueDec;
                    var Squadkpm = response.Stats[Playlist.Squad][Stat.KillsPerMatch].ValueDec;
                    var Squadtrnrating = response.Stats[Playlist.Squad][Stat.TrnRating].Value;

                    var xblSquad = Helpers.CreateEmbed(Context, "**Squad**

Score: " + Squadscore + "
Score Per Match: " + Squadspm + "
K/D: " + Squadkd + "
W/R: "

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not digging into API-specific issues but, if your message is too long then split it and send multiple messages.

You seem to have 3 parts in your message : solo, duo and squad, send one message for each.

If that isn't enough then grab chunks of your final message string, preferably splitting at punctuation/spaces and/or add ellipsis so that your message looks nice to the users reading them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...