Created
July 28, 2016 21:59
-
-
Save naikrovek/9b164f9268f24c4cfe1152ed1f7b0da4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed partial class MainPage : Page { | |
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; | |
DiscordSocketClient _client; | |
string token = ""; | |
public MainPage() { | |
this.InitializeComponent(); | |
_client = new DiscordSocketClient(); | |
SetupEventHandlers(); | |
ConnectAndLogin(); | |
} | |
private void SetupEventHandlers() { | |
_client.MessageReceived += async (message) => { | |
await AppendText(message.Content); | |
//return null; | |
}; | |
_client.Connected += async () => { | |
await AppendText("Connected."); | |
var guilds = await _client.GetGuildsAsync(); | |
try { | |
foreach (var guild in guilds) { | |
await AppendText(guild.Name + " -- " + guild.Id); | |
} | |
} catch (Exception ex) { | |
await AppendText(ex.Message); | |
} | |
await AppendText("Guild list complete."); | |
}; | |
} | |
private async Task ConnectAndLogin() { | |
textBlock.Text = "Running.\n"; | |
await _client.LoginAsync(TokenType.User, token, true); | |
await _client.ConnectAsync(); | |
} | |
private async Task AppendText(string text) { | |
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { | |
textBlock.Text += text + "\n"; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment