Skip to content

4.x Prefer overrides over new modifier #2239

Open
@sabihoshi

Description

@sabihoshi

A majority of entities use the new modifier in order to implement features on their derived types, instead of a virtual function and then overriding it. This causes issues when you have the base class, leading to errors when the derived type's implementation is vastly different. An example is for RestFollowupMessage

RestFollowupMessage m;
await ((IUserMessage)m).ModifyAsync(m => m.Content = "Foo"); // will throw

Which leads you to do something like this

async Task Components(IUserMessage message)
{
    var menu = SelectMenu(user, type);
    var components = GetMessageComponents(message).WithSelectMenu(menu).Build();

    await (message switch
    {
        RestInteractionMessage m => m.ModifyAsync(r => r.Components       = components),
        RestFollowupMessage m    => m.ModifyAsync(r => r.Components       = components),
        _                        => message.ModifyAsync(r => r.Components = components)
    });
}

The call stack for the exception shows that it comes from a RestUserMessage and not from a RestFollowupMessage as example.

Discord.Net.HttpException: The server responded with error 10008: Unknown Message
   at Discord.Net.Queue.RequestBucket.SendAsync(RestRequest request)
   at Discord.Net.Queue.RequestQueue.SendAsync(RestRequest request)
   at Discord.API.DiscordRestApiClient.SendInternalAsync(String method, String endpoint, RestRequest request)
   at Discord.API.DiscordRestApiClient.SendJsonAsync[TResponse](String method, String endpoint, Object payload, BucketId bucketId, ClientBucketType clientBucket, RequestOptions options)
   at Discord.API.DiscordRestApiClient.ModifyMessageAsync(UInt64 channelId, UInt64 messageId, ModifyMessageParams args, RequestOptions options)
   at Discord.Rest.MessageHelper.ModifyAsync(UInt64 channelId, UInt64 msgId, BaseDiscordClient client, Action`1 func, RequestOptions options)
   at Discord.Rest.RestUserMessage.ModifyAsync(Action`1 func, RequestOptions options)

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Planned

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions