Created
September 29, 2022 08:57
-
-
Save MichaelStett/38920b7759c483fed1b1287c0b99ef7c to your computer and use it in GitHub Desktop.
Bot discord
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
using Discord; | |
using Discord.WebSocket; | |
namespace DiscordBotTest; | |
internal class Program | |
{ | |
private const string Token = ""; | |
private readonly DiscordSocketClient _client; | |
public static void Main() | |
=> new Program() | |
.MainAsync() | |
.GetAwaiter() | |
.GetResult(); | |
private Program() | |
{ | |
var config = new DiscordSocketConfig | |
{ | |
GatewayIntents = GatewayIntents.AllUnprivileged | | |
GatewayIntents.MessageContent | |
}; | |
_client = new DiscordSocketClient(config); | |
_client.Log += Log; // log actions | |
_client.Ready += Ready; // fired when connected | |
_client.MessageReceived += MessageReceivedAsync; // when message received | |
} | |
private async Task MainAsync() | |
{ | |
await _client.LoginAsync(TokenType.Bot, Token); | |
await _client.StartAsync(); | |
await Task.Delay(Timeout.Infinite); | |
} | |
private Task Log(LogMessage log) | |
{ | |
Console.WriteLine(log.ToString()); | |
return Task.CompletedTask; | |
} | |
private Task Ready() | |
{ | |
Console.WriteLine($"{_client.CurrentUser} is connected!"); | |
return Task.CompletedTask; | |
} | |
private async Task MessageReceivedAsync(SocketMessage message) | |
{ | |
if (message.Author.Id == _client.CurrentUser.Id) | |
return; | |
if (message.Content == "/give-me-quote") | |
{ | |
await message.Channel.SendMessageAsync( | |
"I'm too old for this shit!\r\n-Sergeant Roger Murtaugh\r\n-Lethal Weapon" | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment