Created
December 9, 2017 22:45
-
-
Save DeltaDizzy/804a5a989f76f934283ba5616166000c to your computer and use it in GitHub Desktop.
help me
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.Commands; | |
using Discord.WebSocket; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
using System.Reflection; | |
using System.Threading.Tasks; | |
namespace DeltaBot | |
{ | |
public class CommandHandler | |
{ | |
private DiscordSocketClient _client; | |
private CommandService _commands; | |
private IServiceProvider _services; | |
string token = "no hackerz allowed"; | |
public CommandHandler(DiscordSocketClient client) | |
{ | |
} | |
public async Task StartAsync() | |
{ | |
_client = new DiscordSocketClient(); | |
_commands = new CommandService(); | |
_services = new ServiceCollection() | |
.AddSingleton(_client) | |
.AddSingleton(_commands) | |
.BuildServiceProvider(); | |
await InstallCommandsAsync(); | |
} | |
public async Task InstallCommandsAsync() | |
{ | |
_client.MessageReceived += HandleCommandAsync; | |
await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); | |
} | |
private async Task HandleCommandAsync() | |
{ | |
var message = messageParam as SocketUserMessage; | |
if (message == null) return; | |
int argPos = 0; | |
if (!(message.HasCharPrefix('&', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))) return; | |
var context = new SocketCommandContext(_client, message); | |
var result = await _commands.ExecuteAsync(context, argPos, _services); | |
if (!result.IsSuccess) | |
await context.Channel.SendMessageAsync(result.ErrorReason); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what