public async Task HelpAsync([Remainder] string command = null) { // TODO: Get command by name var cmds = commands.Commands.OrderBy(x => x.Name); if (command == null) { var s = string.Join("\n", cmds.Select(x => $"`{x.Name}`{(x.Aliases.Count - 1 == 0 ? "" : " - [**" + string.Join(", ", x.Aliases.Skip(1)) + "**]")}: {x.Summary}")); var embed = await embedHelper.BuildMessageEmbed(s); await Context.Channel.SendAndRemove(embed : embed, timeout : 30000); return; } var selectedCmd = cmds.Where(x => x.Name.ToLower() == command || x.Aliases.Contains(command, StringComparer.OrdinalIgnoreCase))?.Select(x => $"`{x.Name}`{(x.Aliases.Count - 1 == 0 ? "" : " - [**" + string.Join(", ", x.Aliases.Skip(1)) + "**]")}: {x.Summary}").FirstOrDefault(); if (selectedCmd != null) { var embed = await embedHelper.BuildMessageEmbed(selectedCmd); await Context.Channel.SendAndRemove(embed : embed, timeout : 15000); return; } var error = await embedHelper.BuildErrorEmbed("Invalid command", $"Command `{command}` is invalid.\nUse `{Program.BotConfig.Prefix}help` to see all commands"); await Context.Channel.SendAndRemove(embed : error, timeout : 15000); }
private async Task MessageReceived(SocketMessage socketMessage) { if (!(socketMessage is SocketUserMessage message)) { return; } if (message.Source != MessageSource.User) { return; } if (message.Author.IsBot) { return; } var context = new SocketCommandContext(discord, message); int argPos = 0; string prefix = Program.BotConfig.Prefix; ulong chId = Program.BotConfig.ChannelId; if (context.Guild.TextChannels.Any(x => x.Id == chId) && message.Channel.Id != chId) { if (message.HasStringPrefix(prefix, ref argPos)) { _ = Task.Run(async() => { await message.DeleteAsync(); var msg = await embedHelper.BuildMessageEmbed($"This command is restricted to <#{chId}>."); await context.Channel.SendAndRemove(embed: msg, timeout: 15000); }); } return; } if (message.Content != $"{prefix}premium" && (message.Author as IGuildUser)?.VoiceChannel == null) { _ = Task.Run(async() => { await message.DeleteAsync(); var msg = await embedHelper.BuildMessageEmbed("You have to be in a voice channel."); await context.Channel.SendAndRemove(embed: msg); }); return; } if (!message.HasStringPrefix(prefix, ref argPos) && context.Guild.TextChannels.Any(x => x.Id == chId)) { _ = Task.Run(async() => { await ah.SearchForTrack(context, message.Content); }); await message.DeleteAsync(); return; } var result = await commands.ExecuteAsync(context, argPos, provider); if (result.Error is CommandError.UnknownCommand) { return; } if (result.Error.HasValue && result.Error.Value != CommandError.UnknownCommand) { // TODO Look at custom parse errors await context.Channel.SendMessageAsync(result.ToString()); } _ = Task.Run(async() => { await message.DeleteAsync(); }); }