Created
January 25, 2021 14:15
-
-
Save joshuaChoiXD/687e333e1c5b3508cb2a1633a468d201 to your computer and use it in GitHub Desktop.
Discord Bot
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 System; | |
using System.Reflection; | |
using System.Threading.Tasks; | |
using Discord; | |
using Discord.Commands; | |
using Discord.WebSocket; | |
using System.Globalization; | |
using System.Linq; | |
using Discord.API; | |
using Discord.Webhook; | |
using Discord.Net; | |
using Discord.Rest; | |
//lol if you find this too many, please forgive me because this code is orginally from my own bot. | |
//How to support Discord on Viusal Studio: Solution Explorer > Dependencies(Right-Click) > Manage NuGet Packages > (Search Discord) > Download all Purple Label, Released by Rogue Exception or Discord.Net Contributors > | |
// > Paste this code. | |
namespace Discord_Bot | |
{ | |
class Program | |
{ | |
private DiscordSocketClient _client; | |
public static void Main(string[] args) | |
=> new Program().MainAsync().GetAwaiter().GetResult(); | |
static void MainDiscord(string[] args) | |
{ | |
new Program().MainAsync().GetAwaiter().GetResult(); | |
} | |
private Task Log(LogMessage msg) | |
{ | |
Console.WriteLine(msg.ToString()); | |
return Task.CompletedTask; | |
} | |
public async Task MainAsync() | |
{ | |
_client = new DiscordSocketClient(); | |
_client.Ready += ReadyAsync; | |
_client.Log += Log; | |
_client.MessageReceived += MessageReceivedAsync; | |
Console.Title = "Discord Bot"; | |
await _client.SetGameAsync("a game"); | |
var token = ""; | |
//Insert your own bot token in the var token. | |
//Bot Token is literally the Password to your bot, so keep it safe. | |
await _client.LoginAsync(TokenType.Bot, token); | |
await _client.StartAsync(); | |
// Block this task until the program is closed. | |
await Task.Delay(-1); | |
} | |
private Task LogAsync(LogMessage log) | |
{ | |
Console.WriteLine(log.ToString()); | |
return Task.CompletedTask; | |
} | |
private Task ReadyAsync() | |
{ | |
Console.WriteLine($"Connected as -> [{_client.CurrentUser}] :)"); | |
return Task.CompletedTask; | |
} | |
private async Task MessageReceivedAsync(SocketMessage message) | |
{ | |
if(message.Content == ";Hello") | |
{ | |
await message.Channel.SendMessageAsync("Hi! I am a Discord Bot!"); | |
} | |
} | |
} | |
} | |
//Run this code and expect your bot to go online. Try entering ;Hello. Your discord bot should send Hi! I am a Discord Bot!. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment