Beispiel #1
0
        public async Task RunAsync()
        {
            ConfigJson configJson = await GetConfig();

            if (Token != null)
            {
                configJson.Token = Token;
                await UpdateConfig(configJson);
            }
            DiscordConfiguration config = new DiscordConfiguration
            {
                Token           = Token ?? configJson.Token,
                TokenType       = TokenType.Bot,
                AutoReconnect   = true,
                MinimumLogLevel = LogLevel.Debug,
            };

            Client                   = new DiscordClient(config);
            Client.Ready            += OnClientReady;
            Client.GuildMemberAdded += OnMemberAdded;

            CommandsNextConfiguration commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = new string[] { configJson.Prefix },
                EnableMentionPrefix = true,
                EnableDms           = false
            };

            Commands = Client.UseCommandsNext(commandsConfig);
            Commands.RegisterCommands <DummyCommands>();

            await Client.ConnectAsync();

            await Task.Delay(-1);
        }
Beispiel #2
0
        private async Task OnMemberAdded(DiscordClient sender, GuildMemberAddEventArgs e)
        {
            ConfigJson config = await GetConfig();

            DiscordMember daryl = await e.Guild.GetMemberAsync(229594828889915392);

            foreach (DSharpPlus.Entities.DiscordInvite discordInvite in await e.Guild.GetInvitesAsync())
            {
                Console.WriteLine(discordInvite.Code + " => " + discordInvite.Inviter.Username);
                if (discordInvite.Uses == invitesCount[discordInvite.Code])
                {
                    continue;
                }
                DiscordRole role = e.Guild.GetRole(config.InviteRole[discordInvite.Code]);
                try
                {
                    await e.Member.GrantRoleAsync(role);
                }
                catch (Exception exception)
                {
                    await daryl.SendMessageAsync($"Failed to grant {role.Name} to {e.Member.Username} \n Error: {exception.Message}");

                    invitesCount[discordInvite.Code] = discordInvite.Uses;
                    return;
                }
                invitesCount[discordInvite.Code] = discordInvite.Uses;
                await daryl.SendMessageAsync($"Granted {role.Name} to {e.Member.Username}");

                return;
            }
            await daryl.SendMessageAsync($"Failed to grant any roles to {e.Member.Username}");
        }
Beispiel #3
0
 public static async Task UpdateConfig(ConfigJson configJson)
 {
     string t = JsonConvert.SerializeObject(configJson);
     await File.WriteAllTextAsync("config.json", t);
 }