A Discord wrapper in C# compatible with UWP.
Api services that do not require authentication can be accessed by doing:
DiscordApiConfiguration config = new DiscordApiConfiguration
{
BaseUrl = "https://discordapp.com/api"
};
BasicRestFactory basicRestFactory = new BasicRestFactory(config);
ILoginService loginService = basicRestFactory.GetLoginService();
IGatewayService gatewayService = basicRestFactory.GetGatewayService();
Note: This is not the planned implantation of the Authentication layer, this is just a band-aid solution till time is found to work on it.
LoginRequest loginRequest = new LoginRequest
{
Email = "EMAIL",
Password = "PASSWORD"
};
LoginResult loginResult = await loginService.Login(loginRequest);
IAuthenticator authenticator = new DiscordAuthenticator(loginResult.Token);
AuthenticatedRestFactory authenticatedRestFactory = new AuthenticatedRestFactory(config, authenticator);
IUserService userService = authenticatedRestFactory.GetUserService();
IGuildService guildService = authenticatedRestFactory.GetGuildService();
IChannelService channelService = authenticatedRestFactory.GetChannelService();
IInviteService inviteService = authenticatedRestFactory.GetInviteService();
To create a Gateway instance, you need a GatewayConfig
and an IAuthenticator
.
GatewayConfig config = await gatewayService.GetGatewayConfigAsync();
Gateway gateway = new Gateway(config, authenticator);
To connect just call:
await gateway.ConnectAsync();
Then events can be listened to as follows:
gateway.MessageCreated += (sender, e) =>
{
Message message = e.EventPayload;
// Handle message
};
- Finish implementing all gateway events
- Make authentication layer so it can securely store authentication state
- Implement Voice
- Remove Universal Windows dependencies and only depend on .NETCore