Ejemplo n.º 1
0
 private Task SlashCommandService_CommandExecuted(SlashCommandsExtension sc, SlashCommandExecutedEventArgs e)
 {
     e.Context.Client.Logger.LogInformation(TestBotEventId, "User {User} executed '{Command}' in {Channel}", e.Context.User.Username, e.Context.CommandName, e.Context.Channel.Name);
     return(Task.CompletedTask);
 }
Ejemplo n.º 2
0
        public static async Task CommandErrored(SlashCommandsExtension slashCommandExtension, SlashCommandExecutedEventArgs slashCommandExecutedEventArgs)
        {
            using IServiceScope scope = Program.ServiceProvider.CreateScope();
            Database database = scope.ServiceProvider.GetService <Database>();

            if (slashCommandExecutedEventArgs.Context.Guild == null)
            {
                return;
            }

            GuildMember guildMember = database.GuildMembers.FirstOrDefault(user => user.UserId == slashCommandExecutedEventArgs.Context.Member.Id && user.GuildId == slashCommandExecutedEventArgs.Context.Guild.Id);

            if (guildMember == null)
            {
                database.AddGuildMember(slashCommandExecutedEventArgs.Context.Member);
                await database.SaveChangesAsync();
            }
            slashCommandExecutedEventArgs.Handled = true;
        }