Пример #1
0
        public async Task AddAutoRole([Remainder] string name)
        {
            await Context.Channel.TriggerTypingAsync();

            var autoRoles = await _autoRolesHelper.GetAutoRolesAsync(Context.Guild);

            var role = Context.Guild.Roles.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.CurrentCultureIgnoreCase));

            if (role == null)
            {
                await ReplyAsync("That role does not exist!");

                return;
            }

            if (role.Position > Context.Guild.CurrentUser.Hierarchy)
            {
                await ReplyAsync("That role has a higher position than the bot!");

                return;
            }

            if (autoRoles.Any(x => x.Id == role.Id))
            {
                await ReplyAsync("That role is already an autorole!");

                return;
            }

            await _autoRoles.AddAutoRoleAsync(Context.Guild.Id, role.Id);

            await ReplyAsync($"The role {role.Mention} has been added to the autoroles!");
        }
Пример #2
0
        public async Task AddAutoRole([Remainder] string name)
        {
            await Context.Channel.TriggerTypingAsync();

            var autoRoles = await _autoRolesHelper.GetAutoRolesAsync(Context.Guild);

            var role = Context.Guild.Roles.FirstOrDefault(x =>
                                                          string.Equals(x.Name, name, StringComparison.CurrentCultureIgnoreCase));

            if (role == null)
            {
                await Context.Channel.SendErrorAsync("Error", "That role does not exist!");

                return;
            }

            if (role.Position > Context.Guild.CurrentUser.Hierarchy)
            {
                await Context.Channel.SendErrorAsync("Error", "That role has a higher position then the bot");

                return;
            }

            if (autoRoles.Any(x => x.Id == role.Id))
            {
                await Context.Channel.SendErrorAsync("Error", "That role is already an autorole");

                return;
            }

            await _autoRoles.AddAutoRoleAsync(Context.Guild.Id, role.Id);

            await Context.Channel.SendSuccessAsync("Success",
                                                   $"The role {role.Mention} has been added to the autoroles!");

            await _serverHelper.SendLogAsync(Context.Guild, "Auto-Role Added",
                                             $"{Context.User.Mention} has added the `{role.Name} role to the auto-role list`");
        }