public CommandHelper(DiscordSocketClient client) { commands = new CommandService(); this.client = client; services = new ServiceCollection() .AddSingleton(client) .AddSingleton(commands) .BuildServiceProvider(); // Manually add commands below commands.AddModuleAsync <Cat>(); commands.AddModuleAsync <AsciiArt>(); commands.AddModuleAsync <Emoticons>(); }
private async Task InstallCommandAsync() { _client.MessageReceived += HandleCommandAsync; // Load command module await _commands.AddModuleAsync <InfoModule>(); }
public async Task RegisterCommandsAsync() { client.MessageReceived += HandleCommandAsync; client.UserJoined += HandleUserJoinedAsync; client.ReactionAdded += (Cacheable <IUserMessage, ulong> cacheableMessage, ISocketMessageChannel channel, SocketReaction reaction) => HandleReactionAsync(cacheableMessage, channel, reaction, true); client.ReactionRemoved += (Cacheable <IUserMessage, ulong> cacheableMessage, ISocketMessageChannel channel, SocketReaction reaction) => HandleReactionAsync(cacheableMessage, channel, reaction, false); await commands.AddModuleAsync(typeof(Modules.Commands), services); }
public async Task Install(DiscordSocketClient client) { this.client = client; commands = new CommandService(); await commands.AddModulesAsync(Assembly.GetEntryAssembly()); await commands.AddModuleAsync(typeof(Modules.CommandModule)); client.MessageReceived += HandleCommand; }
private async Task InitCommands() { // Repeat this for all the service classes // and other dependencies that your commands might need. //_map.AddSingleton(new SomeServiceClass()); // When all your required services are in the collection, build the container. // Tip: There's an overload taking in a 'validateScopes' bool to make sure // you haven't made any mistakes in your dependency graph. _services = _map.BuildServiceProvider(); // Either search the program and add all Module classes that can be found. // Module classes MUST be marked 'public' or they will be ignored. await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); // Or add Modules manually if you prefer to be a little more explicit: //await _commands.AddModuleAsync<SomeModule>(); await _commands.AddModuleAsync <TestModule>(); // Note that the first one is 'Modules' (plural) and the second is 'Module' (singular). // Subscribe a handler to see if a message invokes a command. _client.MessageReceived += HandleCommandAsync; }