Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ((First tab))
- using Discord;
- using Discord.WebSocket;
- using System.Threading.Tasks;
- namespace IMP
- {
- public class Program
- {
- static void Main(string[] args)
- => new Program().StartAsync().GetAwaiter().GetResult();
- private DiscordSocketClient _client;
- private CommandHandler _handler;
- public async Task StartAsync()
- {
- _client = new DiscordSocketClient();
- new CommandHandler(_client);
- await _client.LoginAsync(TokenType.Bot, "xxxxxxxxxxxx");
- await _client.StartAsync();
- _handler = new CommandHandler(_client);
- await Task.Delay(-1);
- }
- }
- }
- ((Second tab))
- using Discord.Commands;
- using Discord.WebSocket;
- using System.Reflection;
- using System.Threading.Tasks;
- namespace IMP
- {
- public class CommandHandler
- {
- private DiscordSocketClient _client;
- private CommandService _service;
- public CommandHandler(DiscordSocketClient client)
- {
- _client = client;
- _service = new CommandService();
- _service.AddModulesAsync(Assembly.GetEntryAssembly());
- _client.MessageReceived += HandleCommandAsync;
- }
- private async Task HandleCommandAsync(SocketMessage s)
- {
- var msg = s as SocketUserMessage;
- if (msg == null) return;
- var context = new SocketCommandContext(_client, msg);
- int argPos = 0;
- if (msg.HasCharPrefix('/', ref argPos))
- {
- var result = await _service.ExecuteAsync(context, argPos);
- if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
- {
- await context.Channel.SendMessageAsync(result.ErrorReason);
- }
- }
- }
- }
- }
- ((Third tab))
- using Discord;
- using Discord.Commands;
- using System.Threading.Tasks;
- namespace IMP.Modules
- {
- public class Test : ModuleBase<SocketCommandContext>
- {
- [Command("UserID")]
- public async Task Bastard(IGuildUser user)
- {
- await Context.Channel.SendMessageAsync(user.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement