• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Discord.DiscordClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: EchoMessage

 private async void EchoMessage(DiscordClient client)
 {
     client.MessageReceived += async (s, e) =>
     {
         if (!e.Message.IsAuthor)
             await client.SendMessage(e.Channel, e.Message.Text);
     };
 }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:8,代码来源:1453330569$Program.cs


示例17: DiscordVoiceSocket

		public DiscordVoiceSocket(DiscordClient client, int timeout, int interval, bool isDebug)
			: base(client, timeout, interval, isDebug)
		{
			_connectWaitOnLogin = new ManualResetEventSlim(false);
#if !DNXCORE50
			_sendQueue = new ConcurrentQueue<Packet>();
			_encoder = new OpusEncoder(48000, 1, 20, Application.Audio);
#endif
		}
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:9,代码来源:DiscordVoiceSocket.cs


示例18: Channel

		internal Channel(DiscordClient client, string id, string serverId, string recipientId)
		{
			_client = client;
			Id = id;
			ServerId = serverId;
			RecipientId = recipientId;
			_messages = new ConcurrentDictionary<string, bool>();
			_areMembersStale = true;
        }
开发者ID:Goobles,项目名称:Discord.Net,代码行数:9,代码来源:Channel.cs


示例19: DiscordWebSocket

		public DiscordWebSocket(DiscordClient client, int timeout, int interval, bool isDebug)
		{
			_client = client;
            _timeout = timeout;
			_sendInterval = interval;
			_isDebug = isDebug;

			_sendQueue = new ConcurrentQueue<byte[]>();
		}
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:9,代码来源:DiscordWebSocket.cs


示例20: Server

		internal Server(string id, DiscordClient client)
		{
			Id = id;
			_client = client;
			_bans = new ConcurrentDictionary<string, bool>();
			_members = new AsyncCache<Membership, API.Models.MemberInfo>(
				(key, parentKey) =>
				{
					if (_client.IsDebugMode)
						_client.RaiseOnDebugMessage(DebugMessageType.Cache, $"Created user {key} in server {parentKey}.");
                    return new Membership(parentKey, key, _client);
				},
				(member, model) =>
				{
					if (model is API.Models.PresenceMemberInfo)
					{
						var extendedModel = model as API.Models.PresenceMemberInfo;
						member.Status = extendedModel.Status;
						member.GameId = extendedModel.GameId;
					}
					if (model is API.Models.VoiceMemberInfo)
					{
						var extendedModel = model as API.Models.VoiceMemberInfo;
						member.VoiceChannelId = extendedModel.ChannelId;
						member.IsDeafened = extendedModel.IsDeafened;
						member.IsMuted = extendedModel.IsMuted;
						if (extendedModel.IsSelfDeafened.HasValue)
							member.IsSelfDeafened = extendedModel.IsSelfDeafened.Value;
						if (extendedModel.IsSelfMuted.HasValue)
							member.IsSelfMuted = extendedModel.IsSelfMuted.Value;
						member.IsSuppressed = extendedModel.IsSuppressed;
						member.SessionId = extendedModel.SessionId;
						member.Token = extendedModel.Token;
					}
					if (model is API.Models.RoleMemberInfo)
					{
						var extendedModel = model as API.Models.RoleMemberInfo;
						member.RoleIds = extendedModel.Roles;
						if (extendedModel.JoinedAt.HasValue)
							member.JoinedAt = extendedModel.JoinedAt.Value;
					}
					if (model is API.Models.InitialMemberInfo)
					{
						var extendedModel = model as API.Models.InitialMemberInfo;
						member.IsDeafened = extendedModel.IsDeafened;
						member.IsMuted = extendedModel.IsMuted;
					}
					if (_client.IsDebugMode)
						_client.RaiseOnDebugMessage(DebugMessageType.Cache, $"Updated user {member.User?.Name} ({member.UserId}) in server {member.Server?.Name} ({member.ServerId}).");
				},
				(member) =>
				{
					if (_client.IsDebugMode)
						_client.RaiseOnDebugMessage(DebugMessageType.Cache, $"Destroyed user {member.User?.Name} ({member.UserId}) in server {member.Server?.Name} ({member.ServerId}).");
				}
			);
		}
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:57,代码来源:Server.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Discord.Server类代码示例发布时间:2022-05-24
下一篇:
C# Discord.Channel类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap