public Task Commands(DiscordClient c, MessageCreateEventArgs e) { _ = Task.Run(async() => { if (e.Author.IsBot || string.IsNullOrEmpty(e.Message.Content)) { return; } CommandsNextExtension cnext = c.GetCommandsNext(); string prefix = _prefixCache.RetrievePrefix(e.Guild?.Id); int prefixLength = e.Channel.IsPrivate ? 0 : // No prefix in DMs, else try to get the string prefix length. // e.MentionedUsers.Any(u => u.Id == c.CurrentUser.Id) ? e.Message.GetMentionPrefixLength(c.CurrentUser) : e.Message.GetStringPrefixLength(prefix); if (prefixLength is - 1) { return; } string commandString = e.Message.Content.Substring(prefixLength); Command?command = cnext.FindCommand(commandString, out string arguments); if (command is null) { _logger.LogWarning($"Command not found: {e.Message.Content}"); return; } CommandContext context = cnext.CreateContext(e.Message, prefix, command, arguments); await cnext.ExecuteCommandAsync(context).ConfigureAwait(false); }); return(Task.CompletedTask); }
public async Task SetPrefix(CommandContext ctx) { string?prefix = _prefixCache.RetrievePrefix(ctx.Guild?.Id); await ctx.RespondAsync($"My prefix is `{prefix}`, but you can always use commands by mentioning me! ({ctx.Client.CurrentUser.Mention})"); }