Repository navigation
Fix #1325 - WebhookBuilder Throws Bad Request - #1363
Conversation
| Content = builder.Content, | ||
| Embeds = builder.Embeds, | ||
| Mentions = builder.Mentions, | ||
| Mentions = new DiscordMentions(builder.Mentions ?? Mentions.All, builder.Mentions?.Any() ?? false), |
There was a problem hiding this comment.
Mentions should still be null if the builder's Mentions are null.
Not only would this otherwise be inconsistent with previous behavior, but editing a webhook without specifying mentions on the builder would now set it to have everyone in the message mentioned.
(Note the NullValueHandling on the payload property.)
| { | ||
| builder.Validate(true); | ||
|
|
||
| var mentions = builder.Mentions != null ? new DiscordMentions(builder.Mentions, builder.Mentions?.Any() ?? false) : null; |
There was a problem hiding this comment.
builder.Mentions?.Any() ?? false should just be builder.Mentions.Any() since null is already checked, though it shouldn't have a functional impact.
Otherwise, LGTM.
|
Tested? |
|
I've only tested it with I'm not familiar with how I go about proving this... here's a picture? My garbage test code if you want it public class SlashMentionTest : ApplicationCommandModule
{
[SlashCommand("mention_test", "Test the webhookbuilder mentions")]
public async Task MentionTestAsync(InteractionContext context, [Option("Array", "Use mention array option")] bool array = false)
{
// your own role ID here
DiscordRole testRole = context.Guild.GetRole(1004897882253570158);
var mentions = new IMention[] { new UserMention(context.User), new UserMention(context.Client.CurrentUser), new RoleMention(testRole) };
// how do you get a mention back from IMention anyway? wish I knew right now ...
string message = array ? $"Hi {context.User.Mention} {context.Client.CurrentUser.Mention} {testRole.Mention}" : $"Hi {context.User.Mention}";
await context.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);
// doin stuff
Thread.Sleep(2000);
var webhookBuilder = new DiscordWebhookBuilder().WithContent(message);
if(array)
{
// use mentions array
webhookBuilder.AddMentions(mentions);
}
else
{
// use single mention
webhookBuilder.AddMention(new UserMention(context.User));
}
await context.EditResponseAsync(webhookBuilder);
}
} |
|
Yeah that works. Thanks for your contributions! |
* Change GuildMemberUpdatedEventArgs to contain before and after DiscordMember objects (#1359) * Fix #1325 - WebhookBuilder Throws Bad Request (#1363) * use DiscordMentions on RestWebhookPayloads * keep null value when null * remove null check from discordmentions arg * Implemented PATCH /guilds/:guild_id/roles (tested) (#1311) * Fix compile errors caused by #1333 * Update hosting.md * Remove unused DSharpPlus.MSTest folder * Cache threads upon thread creation (#1366) * categorization for the cnext default help command (#1371) * Fix memberBefore missing roles in GuildMemberUpdateEventArgs when not… (#1364) * Fix memberBefore missing roles in GuildMemberUpdateEventArgs when not in cache * Update cached guild member in OnGuildMemberUpdateEventAsync internal event handler * Update DiscordClient.Dispatch.cs Co-authored-by: Lunar Starstrum <lunar@forsaken-borders.net> * Ported CommandsNext cooldown attribute to Slash Commands (#1375) * Ported CommandsNext cooldown attribute to Slash Commands; Fixed compiler warnings and suggestions * Still untested; Attempted to resolve @Erisa's review * Made all exceptions inherit from ApplicationCommandExecutionChecksFailedException (previously Exception) * Start on converters * Added custom converter support: - No, I did not implement the checks in the converters. I felt that should be done in a separate area of code - Yes, I did break my Enter, Backspace, D and Apostrophe keys because of this PR. Don't ask how. * Fixed startup errors; Added DiscordMessageArgumentConverter; Added (un)register converter methods (untested). * Fix registering converters * (untested) Add number converters; Fix enums not registering choices correctly * Add DiscordMember converter; Switch from ArgumentException to new MissingArgumentConverterException * Actually fix Nullable and update TimeSpan converter to match with CNext * Add params/array support * Boundry checks * [ci-skip] Resolve naming errors * "One less variable allocation" * Remove unsupport NETSTANDARD1_3 support; Un-Emziware those variable names * Remove unused property * Extra parameter limit attribute check * Remove UnregisterConverter(s) methods * Changed BCL types to use framework names * Pass InnerException to prevent passing TargetInvocationException * Fix enum support (again) --------- Co-authored-by: Bob Loblaw <razvanmandache@gmail.com> Co-authored-by: waffle-lord <76401815+waffle-lord@users.noreply.github.com> Co-authored-by: Iris Féanorá <61018569+ExaInsanity@users.noreply.github.com>

Summary
Fixes #1325 by Changing
RestWebhookPayloads.Mentionsto useDiscordMentionsinstead ofIEnumerable<IMention>Details
the api expects
"users":[],"roles":[], or"parse":[]for the allowed_mentions field. The DiscordJson serializer is populating this field with"id": 123456...instead which is causing an exception when sending the request. This inadvertently keeps the interaction that created the request alive, seemingly forever.Notes
I haven't tested this to any real extent and know very little of this lib... so you know... *shrug