Reputation: 63
I'm trying to write something in C#, a simple console app that will connect to Discord, retrieve a list of all users in a channel (all currently online would suffice, but everyone who has channel access would be even better.) The app does not need to maintain a connection, just jump in, grab the list of user names and jump out.
I've experimented with DiscordSharp, but it doesn't seem to quite be working out. I think I am getting a client connection but I can't seem to find any channels via GetChannelByName or GetChannelByID. I am not set on using DiscordSharp as the only solution, though I do like the library so far.
Upvotes: 4
Views: 16398
Reputation: 642
In a command module you can do this:
public class AllUsers : ModuleBase<SocketCommandContext>
{
public async Task Traitement()
{
var users = Context.Guild.Users;
//you can loop here on users and do the traitement
}
}
Upvotes: 0
Reputation: 10819
A "server" in discord is called a Guild. Per the documentation a Guild
can have a list of Channel objects. In the Channel
object there is a property called recipients
which should give you all users of that channel.
I wouldn't recommend using DiscordSharp because according to their GitHub it is a dead project. They recommend using DSharpPlus or Discord.NET.
I just checked the documentation for Discord.NET and found a few methods you could use:
GetGuildAsync(UInt64, RequestOptions)
: This will get you the RestGuild (server) based on the server ID.
GetChannelAsync(UInt64, RequestOptions)
: This will get you the RestChannel based on the channel ID.
Using either one of these will eventually get you a RestChannel
object that will contain a GetUsersAsync(CacheMode, RequestOptions)
method that will allow you to get the collection of IUSer
Upvotes: 5