Negative request bucket id spam in console.
Created by: nathan130200
Summary
I'm creating hangman game like in D#+, when i call DeleteMessage in message when request bucket become negative and keep looping negative number freezing everything. await xmsg.Result.DeleteAsync();
Details
Using Windows 10 x64, .NET Core 3 (Release Candidate), D#+ 4.x (latest)
Code
if (_interactivity == null)
{
await ctx.RespondAsync($"{ctx.User.Mention} :x: Módulo de interatividade não encontrado.");
return;
}
// sample embed
var deb = new DiscordEmbedBuilder()
.WithDescription(Formatter.Sanitize(new string(_word_temp)) + ": [" + (_index + 1) + "/7]")
.WithAuthor("SkyLar: Hangman", iconUrl: ctx.Client.CurrentUser.GetAvatarUrl(ImageFormat.Png))
.WithFooter($"Jogando com {ctx.User.Username}#{ctx.User.Discriminator} | {_id}", ctx.User.GetAvatarUrl(ImageFormat.Jpeg))
.WithColor(DiscordColor.Orange);
// initial message
var msg = await ctx.RespondAsync(embed: deb);
game:
{
// wait for user input
var xmsg = await _interactivity.WaitForMessageAsync(xm => xm.Author == ctx.User, TimeSpan.FromMinutes(1));
// is timeout? declare game ended
if (xmsg.TimedOut)
{
await ctx.RespondAsync($"{ctx.User.Mention} :x: Tempo limite de jogo excedido.");
return;
}
// check if is valid content.
if (string.IsNullOrEmpty(xmsg.Result.Content))
{
var xerr = await ctx.RespondAsync($"{ctx.User.Mention} :x: Você precisa fornecer uma letra.");
await Task.Delay(3500);
await xerr.DeleteAsync();
// go back to game, if message content isn't valid, just "warn" to user.
goto game;
}
// used to store if user match letter in word.
var _state = false;
// current user input letter
var _letter = xmsg.Result.Content.First();
for (var i = 0; i < _word.Length; i++)
{
// match for letter in final word
if (_letter == _word[i] || char.ToUpperInvariant(_letter) == _word[i] || char.ToLowerInvariant(_letter) == _word[i])
{
_word_temp[i] = _word[i];
_state = true;
}
}
try
{
// delete user input
await xmsg.Result.DeleteAsync();
}
catch { /* prevent exception thrown if bot has no permission to manage messages */ }
// check if final word is current built word
if (new string(_word_temp) == _word)
{
await msg.DeleteAsync();
await ctx.RespondAsync($"{ctx.User.Mention} :tada: Parabéns... Você venceu!"); // declare victory.
return; // stop "game" label.
}
// no tries :( user lost.
if (_index > 7)
{
await msg.DeleteAsync();
await ctx.RespondAsync($"{ctx.User.Mention} :cry: Infelizmente você não acertou! A palavra era `{Formatter.Sanitize(_word)}`");
return; // stop "game" label.
}
// increment tries if has no letter match in final word
if (!_state)
_index++;
// update embed with matched letters and tries count.
deb.WithDescription(Formatter.Sanitize(new string(_word_temp)) + ": [" + (_index) + "/7]");
await msg.ModifyAsync(embed: deb.Build());
// go back to next "round"
goto game;
}
GamesModule.cs: https://pastebin.com/JQL0GcXW Hangman.cs: https://pastebin.com/eVQCFKFJ