【问题标题】:Discord.net cannot initiate RequestOptionsDiscord.net 无法启动 RequestOptions
【发布时间】:2021-03-13 11:06:22
【问题描述】:

您好,我一直在尝试在 Discord.net 中开发一个机器人,到目前为止它做得很好。 虽然我遇到的问题是我正在尝试使用 ITextChannel 中的 GetMessagesAsync 选项。 不幸的是,我不知道如何启动 RequestOptions,我尝试搜索 the documentation 却一无所获。

    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;
        }

我想知道 Discord.net 是否可以使用 around:messageId 雪花功能。

【问题讨论】:

    标签: c# discord.net


    【解决方案1】:

    我从来不需要使用 RequestOptions,我不确定它的作用。此操作不需要它。

    Discord.NET 支持在 After 和 Before 中获取消息,但目前 Around 尚未实现,会抛出 NotImplementedException。

    要使用 Before 或 After,您可以将 overload 用于 GetMessagesAsync,其中包含 Direction 参数。如果您需要 Around 那么我建议您提出两个请求。一个在之前,一个在之后。

    这是一个例子:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-20
      • 2017-09-19
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多