当前位置: 首页>>代码示例>>C#>>正文


C# DiscordClient.Connect方法代码示例

本文整理汇总了C#中Discord.DiscordClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.Connect方法的具体用法?C# DiscordClient.Connect怎么用?C# DiscordClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discord.DiscordClient的用法示例。


在下文中一共展示了DiscordClient.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var inoriBot = new DiscordClient();

            //Display all log messages in the console
            inoriBot.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");

            //Echo back any message received, provided it didn't come from the bot itself


            //Convert our sync method to an async one and block the Main function until the bot disconnects
            inoriBot.Run(async () =>
            {
                while (true)
                {
                    try
                    {
                        await inoriBot.Connect(EMAIL, PASSWORD);
                        await inoriBot.SetGame(1);
                        break;
                    }
                    catch (Exception ex)
                    {
                        inoriBot.LogMessage += (s, e) => Console.WriteLine(String.Concat("Login Failed", ex));
                        await Task.Delay(inoriBot.Config.FailedReconnectDelay);
                    }
                }
            });
        }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:29,代码来源:1453330509$Program.cs

示例2: Main

        static void Main(string[] args)
        {
        var client = new DiscordClient();

        //Display all log messages in the console
        client.LogMessage += (s, e) => Console.WriteLine("[{e.Severity}] {e.Source}: {e.Message}");

        //Echo back any message received, provided it didn't come from the bot itself
        client.MessageReceived += async (s, e) =>
        {
            if (!e.Message.IsAuthor)
            await client.SendMessage(e.Channel, e.Message.Text);
        };

        //Convert our sync method to an async one and block the Main function until the bot disconnects
        client.Run(async () =>
        {
            //Connect to the Discord server using our email and password
            await client.Connect(EMAIL, PASSWORD);
            client.SetGame(1);

            //If we are not a member of any server, use our invite code (made beforehand in the official Discord Client)
            /*
            if (!client.AllServers.Any())
            await client.AcceptInvite(client.GetInvite(TL_SOKU_INVITE_CODE));
             */
        });
        }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:28,代码来源:1453329945$Program.cs

示例3: Main

        static void Main(string[] args)
        {
        var client = new DiscordClient();

        //Display all log messages in the console
        client.LogMessage += (s, e) => Console.WriteLine("[{e.Severity}] {e.Source}: {e.Message}");

        //Echo back any message received, provided it didn't come from the bot itself
        client.MessageReceived += async (s, e) =>
        {
            if (!e.Message.IsAuthor)
            await client.SendMessage(e.Channel, e.Message.Text);
        };

        //Convert our sync method to an async one and block the Main function until the bot disconnects
        client.Run(async () =>
        {
            while (true)
            {
                try
                {
                    await client.Connect(EMAIL, PASSWORD);
                    client.SetGame("Discord.Net);
                    break;
                }
                catch (Exception ex)
                {
                    client.LogMessage += (s, e) => Console.WriteLine(String.Concat("Login Failed", ex.Message));
                    await Task.Delay(client.Config.FailedReconnectDelay);
                }
            }
        });
        }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:33,代码来源:1453330073$Program.cs

示例4: BauwsBot

        //connects the bot and then logs the chat
        public BauwsBot()
        {
            bot = new DiscordClient();

            bot.MessageReceived += Bot_MessageReceived;

            bot.Connect("[email protected]", "loveall4god123");

            bot.Wait();
        }
开发者ID:RivenSenpai,项目名称:DiscordBot,代码行数:11,代码来源:BauwsBot.cs

示例5: InitBot

        public static void InitBot()
        {

            bot = new DiscordClient();

            bot.MessageReceived += Bot_MessagedReceived;

            bot.ExecuteAndWait(async () => {
                await bot.Connect(discordBotToken);
            });
        }
开发者ID:RyanStewartAlex,项目名称:Carbon-Bot,代码行数:11,代码来源:Program.cs

示例6: DiscoBot

        // This code is executed when the bot is created.
        public DiscoBot()
        {
            // Bot connects using Bot Token.
            bot = new DiscordClient();

            // In place of the ("") put your Bot Token.
            bot.Connect("");
          bot.MessageReceived += bot_MessageReceived;
          bot.Wait();
          

        }
开发者ID:Rithari,项目名称:CryptoBot3.0,代码行数:13,代码来源:DiscoBot.cs

示例7: onLoggedOn

        public override bool onLoggedOn()
        {
            client = new DiscordClient();
            client.Connect(Options.DiscordOptions.Token);

            client.Ready += Client_Ready;
            client.MessageReceived += Client_MessageReceived;
            client.UserJoined += Client_UserJoined;
            client.UserLeft += Client_UserLeft;
            client.ChannelUpdated += Client_ChannelUpdated;
            client.UserUpdated += Client_UserUpdated;
            client.UserBanned += Client_UserBanned;

            return true;
        }
开发者ID:Steam-Chat-Bot,项目名称:SteamChatBot,代码行数:15,代码来源:DiscordTrigger.cs

示例8: Connect

 private async void Connect(DiscordClient inoriClient)
 {
     inoriClient.Run(async () =>
     {
         while (true)
         {
             try
             {
                 await inoriClient.Connect(EMAIL, PASSWORD);
                 await inoriClient.SetGame(1);
                 break;
             }
             catch (Exception ex)
             {
                 inoriClient.LogMessage += (s, e) => Console.WriteLine(String.Concat("Login Failed", ex));
                 await Task.Delay(inoriClient.Config.FailedReconnectDelay);
             }
         }
     });
 }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:20,代码来源:1453330569$Program.cs

示例9: Init

 public void Init(YAMLConfiguration conf)
 {
     try
     {
         Config = conf;
         string token = Config.ReadString("discord.token", null);
         if (token == null)
         {
             Logger.Output(LogType.INFO, "Discord bot not configured!");
             return;
         }
         Client = new DiscordClient();
         Client.MessageReceived += messageReceived;
         Client.ExecuteAndWait(async () => await Client.Connect(token, TokenType.Bot));
     }
     catch (Exception ex)
     {
         Logger.Output(LogType.ERROR, ex.ToString());
     }
 }
开发者ID:DenizenScript,项目名称:DenizenIRCBot,代码行数:20,代码来源:dDiscordBot.cs

示例10: ShowDialog

        public override async void ShowDialog()
        {
            LoginDialog dialog = new LoginDialog();

            if (dialog.ShowDialog() == true)
            {
                _client = new DiscordClient();
                _client.UsingAudio(x =>
                {
                    x.Mode = AudioMode.Outgoing;
                    x.Bitrate = null;
                    x.Channels = 2;
                });

                await _client.Connect(dialog.Username, dialog.Password);
                var voiceChannel = CurrentServer.VoiceChannels.FirstOrDefault(d => d.Name == "Bot Test");

                _voiceClient = await _client.GetService<AudioService>()
                    .Join(voiceChannel);
            }
        }
开发者ID:jmazouri,项目名称:Picofy,代码行数:21,代码来源:PicofyDiscord.cs

示例11: Main

 static void Main(string[] args)
 {
     LoadData();
     _bot = new DiscordClient();
     Console.Write("Email: ");
     email = Console.ReadLine();
     Console.Write("Password: ");
     password = getPassword();
     Console.WriteLine("\nConnecting to Discord...");
     try
     {
         _bot.Connect(email, ConvertToUnsecureString(password));
         Console.WriteLine("Connected!");
     }
     catch
     {
         Console.WriteLine("Connection failed, please try again.");
         System.Environment.Exit(-1);
     }
     Running();
 }
开发者ID:buttsj,项目名称:DiscordBotConsole,代码行数:21,代码来源:Program.cs

示例12: Connect

        public void Connect()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            CommandListInit();
            try
            {
                if (!Properties.Settings.Default.DateTimeFormatCorrected)
                {
                    //xmlprovider.DateTimeCorrection();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            _streamProviderManager = new StreamProviderManager();
            _streamProviderManager.StreamStarted += OnStreamStarted;
            _streamProviderManager.StreamStopped += OnStreamStopped;
            _streamProviderManager.StreamGlobalNotification += OnStreamGlobalNotification;
            _streamProviderManager.AddStreamProvider(new TwitchProvider());
            _streamProviderManager.AddStreamProvider(new HitboxProvider());
            bot = new DiscordClient();
            bot.MessageReceived += Message_Received;
            bot.UserJoined += User_Joined;
            deathmicirc = new RelayBot(bot,false);
            Thread RelayThread = new Thread(deathmicirc.runBot);
            RelayThread.Start();
            while (!RelayThread.IsAlive) ;
            Thread.Sleep(1);

            readUsers();

            bot.ExecuteAndWait(async () =>
            {
                await bot.Connect("MjYwMTE2OTExOTczNDY2MTEy.CzhvyA.kpEIti2hVnjNIUccob0ERB4QFTw", TokenType.Bot);
            });
        }
开发者ID:Kolpa,项目名称:DeathmicChatbot,代码行数:38,代码来源:DiscordBob.cs

示例13: Connect

        private void Connect()
        {
            _client = new DiscordClient();

            //Convert our sync method to an async one and block the Main function until the bot disconnects

            _client.Ready += _client_Ready;
            try
            {
                _client.Connect(BasicTeraData.Instance.WindowData.DiscordLogin, BasicTeraData.Instance.WindowData.DiscordPassword);
            }
            catch (Exception e)
            {

                //Failing here is not a reason to make the meter crash
                BasicTeraData.LogError(e.Message + "\n" + e.StackTrace + "\n" + e.InnerException + "\n" + e, false, false);
                return;
            }
            while (!_ready)
            {
                Thread.Sleep(1000);
            }
        }
开发者ID:neowutran,项目名称:ShinraMeter,代码行数:23,代码来源:Discord.cs

示例14: Start

        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:");
        }
开发者ID:Cappucirno,项目名称:moetron,代码行数:64,代码来源:Program.cs

示例15: Main

        static void Main() {
            //load credentials from credentials.json
            bool loadTrello = false;
            try {
                creds = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json"));
                botMention = creds.BotMention;
                if (string.IsNullOrWhiteSpace(creds.GoogleAPIKey)) {
                    Console.WriteLine("No google api key found. You will not be able to use music and links won't be shortened.");
                } else {
                    Console.WriteLine("Google API key provided.");
                    GoogleAPIKey = creds.GoogleAPIKey;
                }
                if (string.IsNullOrWhiteSpace(creds.TrelloAppKey)) {
                    Console.WriteLine("No trello appkey found. You will not be able to use trello commands.");
                } else {
                    Console.WriteLine("Trello app key provided.");
                    TrelloAppKey = creds.TrelloAppKey;
                    loadTrello = true;
                }
                if (creds.ForwardMessages != true)
                    Console.WriteLine("Not forwarding messages.");
                else {
                    ForwardMessages = true;
                    Console.WriteLine("Forwarding messages.");
                }
                if(string.IsNullOrWhiteSpace(creds.SoundCloudClientID))
                    Console.WriteLine("No soundcloud Client ID found. Soundcloud streaming is disabled.");
                else
                    Console.WriteLine("SoundCloud streaming enabled.");

                OwnerID = creds.OwnerID;
                password = creds.Password;
            } catch (Exception ex) {
                Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}");
                Console.ReadKey();
                return;
            }

            //create new discord client
            client = new DiscordClient(new DiscordConfigBuilder() {
                MessageCacheSize = 0,
                ConnectionTimeout = 60000,
            });

            //create a command service
            var commandService = new CommandService(new CommandServiceConfigBuilder {
                AllowMentionPrefix = false,
                CustomPrefixHandler = m => 0,
                HelpMode = HelpMode.Disabled
            });
            
            //reply to personal messages and forward if enabled.
            client.MessageReceived += Client_MessageReceived;

            //add command service
            var commands = client.Services.Add<CommandService>(commandService);

            //create module service
            var modules = client.Services.Add<ModuleService>(new ModuleService());

            //add audio service
            var audio = client.Services.Add<AudioService>(new AudioService(new AudioServiceConfigBuilder()  {
                Channels = 2,
                EnableEncryption = false,
                EnableMultiserver = true,
                Bitrate = 128,
            }));

            //install modules
            modules.Add(new Administration(), "Administration", ModuleFilter.None);
            modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None);
            modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
            modules.Add(new Gambling(), "Gambling", ModuleFilter.None);
            modules.Add(new Games(), "Games", ModuleFilter.None);
            modules.Add(new Music(), "Music", ModuleFilter.None);
            modules.Add(new Searches(), "Searches", ModuleFilter.None);
            if (loadTrello)
                modules.Add(new Trello(), "Trello", ModuleFilter.None);
            modules.Add(new NSFW(), "NSFW", ModuleFilter.None);

            //run the bot
            client.ExecuteAndWait(async () => {
                await client.Connect(creds.Username, creds.Password);
                Console.WriteLine("-----------------");
                Console.WriteLine(NadekoStats.Instance.GetStats());
                Console.WriteLine("-----------------");

                try {
                    OwnerPrivateChannel = await client.CreatePrivateChannel(OwnerID);
                } catch  {
                    Console.WriteLine("Failed creating private channel with the owner");
                }

                Classes.Permissions.PermissionsHandler.Initialize();

                client.ClientAPI.SendingRequest += (s, e) =>
                {
                    var request = e.Request as Discord.API.Client.Rest.SendMessageRequest;
                    if (request != null) {
                        if (string.IsNullOrWhiteSpace(request.Content))
//.........这里部分代码省略.........
开发者ID:Daedren,项目名称:NadekoBot,代码行数:101,代码来源:NadekoBot.cs


注:本文中的Discord.DiscordClient.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。