【问题标题】:How to retrieve a list of discord users in a channel如何检索频道中的不和谐用户列表
【发布时间】:2018-11-23 05:36:06
【问题描述】:

我正在尝试用 C# 编写一些东西,这是一个简单的控制台应用程序,它将连接到 Discord,检索频道中所有用户的列表(所有当前在线就足够了,但每个拥有频道访问权限的人都会更好。 ) 应用不需要保持连接,直接跳进去,抓取用户名列表跳出来。

我已经尝试过 DiscordSharp,但似乎效果不佳。我想我正在建立一个客户端连接,但我似乎无法通过 GetChannelByName 或 GetChannelByID 找到任何频道。我没有打算使用 DiscordSharp 作为唯一的解决方案,尽管到目前为止我确实喜欢这个库。

【问题讨论】:

标签: c# discord


【解决方案1】:

discord 中的“服务器”称为Guild。根据文档,Guild 可以有一个 Channel 对象列表。在Channel 对象中有一个名为recipients 的属性,它应该为您提供该频道的所有用户。

我不建议使用 DiscordSharp,因为 according to their GitHub 这是一个死项目。他们建议使用DSharpPlusDiscord.NET

我刚刚检查了 the documentation 的 Discord.NET 并找到了一些您可以使用的方法:

GetGuildAsync(UInt64, RequestOptions):这将根据服务器 ID 为您获取 RestGuild(服务器)。

GetChannelAsync(UInt64, RequestOptions):这将根据频道 ID 为您提供 RestChannel

使用其中任何一个最终都会为您获得一个 RestChannel 对象,该对象将包含一个 GetUsersAsync(CacheMode, RequestOptions) 方法,该方法将允许您获取 IUSer 的集合

【讨论】:

    【解决方案2】:

    在命令模块中你可以这样做:

    public class AllUsers : ModuleBase<SocketCommandContext>
    {
        public async Task Traitement()
        {
            var users = Context.Guild.Users; 
            //you can loop here on users and do the traitement
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-10
      • 2021-04-06
      • 1970-01-01
      • 2021-11-23
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      相关资源
      最近更新 更多