Discord bot just show discord version
I have programmed a discord bot and try to connect to my server. But as I try to connect, I just got the Discord version Discord.Net v2.1.1 (API v6) shown and the program is stuck on the line await _client.LoginAsync(TokenType.Bot, bot_token); forever. Here is the complete code:
public class discord
{
private const string bot_token = "<token>";
public delegate void getMessage(string message);
public event getMessage ongetmessage;
private DiscordSocketClient _client;
public async Task MainAsync()
{
_client = new DiscordSocketClient(new DiscordSocketConfig() { LogLevel = LogSeverity.Verbose });
_client.Log += Log;
await _client.LoginAsync(TokenType.Bot, bot_token);
await _client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}
private Task Log(LogMessage msg)
{
ongetmessage(msg.ToString());
return Task.CompletedTask;
}
public void connect()
{
MainAsync().GetAwaiter().GetResult();
}
}
And here is the code from the form:
private void Discord_ongetmessage(string message)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(Discord_ongetmessage), new object[] { message });
return;
}
this.richTextBox1.AppendText(DateTime.Now + ": " + message + "\n");
}
private void btn_connect_Click(object sender, EventArgs e)
{
discord.connect();
}
I am using nuget package Discord.net v2.1.1 and Discord.net.core v2.1.1.
Please sign in to leave a comment.
Comments
0 comments