Search code examples
c#discord.net

Discord.net cannot initiate RequestOptions


Hello i've been trying to dev a bot in Discord.net and it's been doing good so far. Though issue that i had is that i'm trying to use the GetMessagesAsync from ITextChannel using an option. Unfortunately i have no idea how to initiate RequestOptions and i try to search the documentation and found nothing.

    private ulong SearchMessageByMessageLink(ulong messageId, ITextChannel channel)
        {
            var messageList = GetMessagesAsync(100, channel,options:[{around:messageId}]);//fix
            return 1;
        }

    public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong id, ITextChannel channel,  RequestOptions options)
        {
            CacheMode mode = CacheMode.AllowDownload;
            IAsyncEnumerable<IReadOnlyCollection<IMessage>> messageList = channel.GetMessagesAsync(100, mode, options);
            return messageList;
        }

I'm wondering if Discord.net can use the around:messageId snowflake feature.


Solution

  • I've never needed to use RequestOptions and I'm not sure what it does. You don't need it for this action.

    Discord.NET supports getting messages After and Before, but as of yet Around is not yet implemented and will throw a NotImplementedException.

    To use Before or After, you can use an overload for GetMessagesAsync which contains a Direction parameter. If you need Around then I recommend making two requests. One with Before and one with After.

    Here's an example:

    await channel.GetMessagesAsync(afterMessage.Id, Direction.After, count).FlattenAsync()