public BotConnect() { _config = new Settings(); _client = new DiscordClient(x => { x.AppName = "Ethereal"; x.LogLevel = LogSeverity.Info; }) .UsingCommands(x => { x.PrefixChar = _config.Prefix; x.HelpMode = HelpMode.Public; }) .UsingPermissionLevels((u, c) => (int)GetPermission(u, c)) .UsingModules(); _client.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] [{e.Source}] [Bot] {e.Message}"); _client.AddModule <Modules.Commands>("Commands", ModuleFilter.None); _client.UserJoined += _client_UserJoined; _client.UserUpdated += _client_UserUpdated; _client.RoleUpdated += _client_RoleUpdated; //_client.MessageReceived += _client_MsgReceived; _client.ExecuteAndWait(async() => { while (true) { try { await _client.Connect(_config.BotToken, TokenType.Bot); _client.SetGame(_config.CurrentGame, GameType.Twitch, _config.DiscordUrl); UserConnect userConnect = new UserConnect(); return; } catch (Exception ex) { _client.Log.Error("Failed to log in", ex); await Task.Delay(_client.Config.FailedReconnectDelay); } } }); }
public void Start() { const string configFile = "configuration.json"; try { _config = Configuration.LoadFile(configFile); // Load the configuration from a saved file. } catch { _config = new Configuration(); // Create a new configuration file if it doesn't exist. Console.WriteLine("Config file created. Enter a token."); Console.Write("Token: "); _config.Token = Console.ReadLine(); // Read the user's token from the console. _config.SaveFile(configFile); } _client = new DiscordClient(x => // Create a new instance of DiscordClient { x.AppName = "Moetron"; x.AppUrl = "https://github.com/Cappucirno/moetron"; x.AppVersion = "1.0"; x.LogLevel = LogSeverity.Info; // Mirror relevant information to the console. }) .UsingCommands(x => // Configure the Commands extension { x.PrefixChar = _config.Prefix; // Set the prefix from the configuration file x.HelpMode = HelpMode.Private; // Enable the automatic `!help` command. }) .UsingPermissionLevels((u, c) => (int)GetPermission(u, c)) // Permission levels are used to check basic or custom permissions .UsingModules(); // Configure the Modules extension // With LogLevel enabled, mirror info to the console in this format. _client.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); // Load modules into the Modules extension. _client.AddModule<AdminModule>("Admin", ModuleFilter.None); _client.AddModule<EventModule>("Events", ModuleFilter.None); _client.AddModule<PointModule>("Points", ModuleFilter.None); _client.AddModule<ImageModule>("Images", ModuleFilter.None); _client.AddModule<UtilModule>("Utility", ModuleFilter.None); // Proper Login.md _client.ExecuteAndWait(async () => { while (true) { try { await _client.Connect(_config.Token, TokenType.Bot); break; } catch (Exception ex) { _client.Log.Error("Login Failed", ex); await Task.Delay(_client.Config.FailedReconnectDelay); } } }); //_client.SetGame("with your :heart:"); }
private void Start(string[] args) { #if !DNXCORE50 Console.Title = $"{AppName} (Discord.Net v{DiscordConfig.LibVersion})"; #endif GlobalSettings.Load(); _client = new DiscordClient(x => { x.AppName = AppName; x.AppUrl = AppUrl; x.MessageCacheSize = 0; x.UsePermissionsCache = true; x.EnablePreUpdateEvents = true; x.LogLevel = LogSeverity.Debug; x.LogHandler = OnLogMessage; }) .UsingCommands(x => { x.AllowMentionPrefix = true; x.HelpMode = HelpMode.Public; x.ExecuteHandler = OnCommandExecuted; x.ErrorHandler = OnCommandError; }) .UsingModules() .UsingAudio(x => { x.Mode = AudioMode.Outgoing; x.EnableMultiserver = true; x.EnableEncryption = true; x.Bitrate = AudioServiceConfig.MaxBitrate; x.BufferLength = 10000; }) .UsingPermissionLevels(PermissionResolver); _client.AddService<SettingsService>(); _client.AddService<HttpService>(); _client.AddModule<AdminModule>("Admin", ModuleFilter.ServerWhitelist); _client.AddModule<ColorsModule>("Colors", ModuleFilter.ServerWhitelist); _client.AddModule<FeedModule>("Feeds", ModuleFilter.ServerWhitelist); _client.AddModule<GithubModule>("Repos", ModuleFilter.ServerWhitelist); _client.AddModule<ModulesModule>("Modules", ModuleFilter.None); _client.AddModule<PublicModule>("Public", ModuleFilter.None); _client.AddModule<TwitchModule>("Twitch", ModuleFilter.ServerWhitelist); _client.AddModule<StatusModule>("Status", ModuleFilter.ServerWhitelist); //_client.AddModule(new ExecuteModule(env, exporter), "Execute", ModuleFilter.ServerWhitelist); #if PRIVATE PrivateModules.Install(_client); #endif //Convert this method to an async function and connect to the server //DiscordClient will automatically reconnect once we've established a connection, until then we loop on our end //Note: ExecuteAndWait is only needed for Console projects as Main can't be declared as async. UI/Web applications should *not* use this function. _client.ExecuteAndWait(async () => { while (true) { try { await _client.Connect(GlobalSettings.Discord.Email, GlobalSettings.Discord.Password); _client.SetGame("Discord.Net"); //await _client.ClientAPI.Send(new Discord.API.Client.Rest.HealthRequest()); break; } catch (Exception ex) { _client.Log.Error($"Login Failed", ex); await Task.Delay(_client.Config.FailedReconnectDelay); } } }); }