I would like to retrieve users in discord guild but I get an error with cryptic message.
The server responded with error 50001: Missing Access
The bot has Administrator permission, that's what it states in Server settings > Roles > Permissions
Perhaps something else is needed to tick off in configuration.
Your thoughts?
Thanks for help.
Code
class Program
{
private static IDiscordClient _client;
private static bool _isRunning = false;
private static Timer _timer;
static async Task Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(ProcessExit);
var client = new DiscordSocketClient(new DiscordSocketConfig()
{
AlwaysDownloadUsers = true,
MessageCacheSize = 200,
});
var botToken = "...";
await client.LoginAsync(TokenType.Bot, botToken);
await client.StartAsync();
client.Ready += Ready;
_client = client;
await Task.Delay(Timeout.InfiniteTimeSpan);
}
private static async Task Ready()
{
_timer = new Timer(GetUsers, null, TimeSpan.Zero, TimeSpan.FromSeconds(10));
}
private static async void GetUsers(object state)
{
if (_isRunning)
{
return;
}
_isRunning = true;
try
{
var guilds = await _client.GetGuildsAsync();
var guild = guilds.First();
var users = await guild.GetUsersAsync();
Console.WriteLine(users.Count);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
_isRunning = false;
}
static void ProcessExit(object sender, EventArgs e)
{
(_client as DiscordSocketClient).LogoutAsync().GetAwaiter().GetResult();
}
}
Discord Developer Portal - Scopes and bot permissions under OAuth2 configuration
Link which I used to invite bot to server.
https://discord.com/oauth2/authorize?client_id=<>&permissions=8&scope=applications.commands%20bot

