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


C# Discord.DiscordClient类代码示例

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


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

示例1: 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

示例2: StormBot

        public StormBot(string email, string password)
        {
            _email = email;
            _password = password;

            Client = new DiscordClient(config => { config.LogLevel = LogSeverity.Debug; });
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:7,代码来源:StormBot.cs

示例3: Main

        static void Main(string[] args)
        {
            Playlist = new List<string>();
            var inoriClient = new DiscordClient(x =>
            {
                x.AppName = "MilliaBot";
                x.MessageCacheSize = 0;
                x.UsePermissionsCache = true;
                x.EnablePreUpdateEvents = true;
                x.LogLevel = LogSeverity.Debug;
            })
                .UsingCommands(x =>
                {
                    x.AllowMentionPrefix = true;
                    x.HelpMode = HelpMode.Public;
                })
                .UsingModules();

            inoriClient.AddService<AudioService>(new AudioService(new AudioServiceConfigBuilder()
            {
                Channels = 2,
                EnableEncryption = false,
                EnableMultiserver = false,
                Bitrate = 96,
            }));

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

            HandleMessage(inoriClient);

            //Convert our sync method to an async one and block the Main function until the bot disconnects
            Connect(inoriClient);
        }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:34,代码来源:MilliaBot.cs

示例4: Channel

		internal Channel(string id, string serverId, DiscordClient client)
		{
			Id = id;
			ServerId = serverId;
			IsPrivate = serverId == null;
			_client = client;
		}
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:7,代码来源:Channel.cs

示例5: Invite

		internal Invite(DiscordClient client, string code, string xkcdPass, string serverId)
		{
			_client = client;
			Id = code;
			XkcdPass = xkcdPass;
			ServerId = serverId;
		}
开发者ID:Goobles,项目名称:Discord.Net,代码行数:7,代码来源:Invite.cs

示例6: Role

		internal Role(string id, string serverId, DiscordClient client)
		{
			Permissions = new PackedPermissions();
			Id = id;
			ServerId = serverId;
			_client = client;
		}
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:7,代码来源:Role.cs

示例7: TwitchRelay

 public TwitchRelay(DiscordClient discord, string channel, string targetchannel, bool twoway = true)
 {
     sChannel = channel;
     sTargetChannel = targetchannel;
     discordclient = discord;
     bTwoWay = twoway;
 }
开发者ID:Kolpa,项目名称:DeathmicChatbot,代码行数:7,代码来源:TwitchRelay.cs

示例8: 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

示例9: Channel

		internal Channel(DiscordClient client, string id, string serverId, string recipientId)
			: base(client, id)
		{
			_server = new Reference<Server>(serverId, 
				x => _client.Servers[x], 
				x => x.AddChannel(this), 
				x => x.RemoveChannel(this));
			_recipient = new Reference<User>(recipientId, 
				x => _client.Users.GetOrAdd(x, _server.Id), 
				x =>
				{
					Name = "@" + x.Name;
					if (_server.Id == null)
						x.GlobalUser.PrivateChannel = this;
				},
				x =>
				{
					if (_server.Id == null)
						x.GlobalUser.PrivateChannel = null;
                });
			_permissionOverwrites = _initialPermissionsOverwrites;
			_areMembersStale = true;

			//Local Cache
			_messages = new ConcurrentDictionary<string, Message>();
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:26,代码来源:Channel.cs

示例10: User

		internal User(string id, DiscordClient client)
		{
			Id = id;
			_client = client;
			LastActivity = DateTime.UtcNow;
			IsVerified = true;
        }
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:7,代码来源:User.cs

示例11: 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

示例12: Invite

		internal Invite(DiscordClient client, string code, string xkcdPass, string serverId, string inviterId, string channelId)
			: base(client, code)
		{
			XkcdCode = xkcdPass;
			_server = new Reference<Server>(serverId, x =>
			{
				var server = _client.Servers[x];
				if (server == null)
				{
					server = _generatedServer = new Server(client, x);
					server.Cache();
				}
				return server;
			});
			_inviter = new Reference<User>(serverId, x =>
			{
				var inviter = _client.Users[x, _server.Id];
				if (inviter == null)
				{
					inviter = _generatedInviter = new User(client, x, _server.Id);
					inviter.Cache();
				}
				return inviter;
			});
			_channel = new Reference<Channel>(serverId, x =>
			{
				var channel = _client.Channels[x];
				if (channel == null)
				{
					channel = _generatedChannel = new Channel(client, x, _server.Id, null);
					channel.Cache();
				}
				return channel;
			});
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:35,代码来源:Invite.cs

示例13: ConvertToNames

		internal static string ConvertToNames(DiscordClient client, Server server, string text)
		{
			text = _userRegex.Replace(text, new MatchEvaluator(e =>
			{
				string id = e.Value.Substring(2, e.Value.Length - 3);
				var user = client.Users[id, server?.Id];
				if (user != null)
					return '@' + user.Name;
				else //User not found
					return '@' + e.Value;
			}));
			if (server != null)
			{
				text = _channelRegex.Replace(text, new MatchEvaluator(e =>
				{
					string id = e.Value.Substring(2, e.Value.Length - 3);
					var channel = client.Channels[id];
					if (channel != null && channel.Server.Id == server.Id)
						return '#' + channel.Name;
					else //Channel not found
					return '#' + e.Value;
				}));
			}
			return text;
		}
开发者ID:WSIContractor,项目名称:Discord.Net,代码行数:25,代码来源:Mention.cs

示例14: Member

		internal Member(DiscordClient client, string userId, string serverId)
		{
			_client = client;
			UserId = userId;
			ServerId = serverId;
			Status = UserStatus.Offline;
			_permissions = new ConcurrentDictionary<string, PackedPermissions>();
        }
开发者ID:Goobles,项目名称:Discord.Net,代码行数:8,代码来源:Member.cs

示例15: Role

		internal Role(DiscordClient client, string id, string serverId, bool isEveryone)
		{
			_client = client;
			Id = id;
			ServerId = serverId;
			Permissions = new PackedPermissions(true);
			IsEveryone = isEveryone;
        }
开发者ID:Goobles,项目名称:Discord.Net,代码行数:8,代码来源:Role.cs


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