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

C# Discord.Server类代码示例

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

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



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

示例1: MuteUser

        async Task MuteUser(Server server, Channel channel, User user, DateTime expiresOn)
        {
            try
            {
                // TODO: need to check if client has permissions and user is not the owner
                var mutedRole = server.Roles.SingleOrDefault(r => r.Name == "Muted") 
                    ?? await CreateMutedRole(server);

                var punishment = new Punishment
                {
                    Id = Guid.NewGuid(),
                    Server = server,
                    Channel = channel,
                    User = user,
                    RolesBefore = user.Roles,
                    RolesAfter = new List<Role> { mutedRole },
                    ExpiresOn = expiresOn,
                    PunishmentType = PunishmentType.Mute,
                    Actioned = false
                };

                _botServices.Defence.PunishUser(punishment);

                await _client.EditUser(user, null, null, punishment.RolesAfter);
            } 
            catch (Exception ex)
            {
                _botServices.Logging.LogError(string.Format("Failed to add '{0} to the muted role'", user.Name), ex);
                throw;
            }
        }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:31,代码来源:DefenceModule.cs


示例2: CreateInvite

		/// <summary> Creates a new invite to the default channel of the provided server. </summary>
		/// <param name="maxAge"> Time (in seconds) until the invite expires. Set to 0 to never expire. </param>
		/// <param name="tempMembership"> If true, a user accepting this invite will be kicked from the server after closing their client. </param>
		/// <param name="hasXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to 0. </param>
		/// <param name="maxUses"> The max amount  of times this invite may be used. Set to 0 to have unlimited uses. </param>
		public Task<Invite> CreateInvite(Server server, int maxAge = 1800, int maxUses = 0, bool tempMembership = false, bool hasXkcd = false)
		{
			if (server == null) throw new ArgumentNullException(nameof(server));
			CheckReady();

			return CreateInvite(server.DefaultChannel, maxAge, maxUses, tempMembership, hasXkcd);
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:12,代码来源:DiscordClient.Invites.cs


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


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


示例5: ValidateUser

 internal static User ValidateUser(Server server, string userName) {
     if (string.IsNullOrWhiteSpace(userName))
         throw new ArgumentNullException(nameof(userName));
     var user = server.FindUsers(userName).FirstOrDefault();
     if (user == null)
         throw new NullReferenceException("That user does not exist.");
     return user;
 }
开发者ID:ZR2,项目名称:l,代码行数:8,代码来源:PermissionHelper.cs


示例6: Role

		internal Role(ulong id, Server server)
		{
            Id = id;
            Server = server;

			Permissions = new ServerPermissions(0);
			Color = new Color(0);
		}
开发者ID:Carbonitex,项目名称:Discord.Net,代码行数:8,代码来源:Role.cs


示例7: GetChannelPermissionsById

        internal static Permissions GetChannelPermissionsById(Server server, ulong id) {
            if (!_permissionsDict.ContainsKey(server))
                return null;

            Permissions toReturn;
            _permissionsDict[server].ChannelPermissions.TryGetValue(id, out toReturn);
            return toReturn;
        }
开发者ID:TheFerty7,项目名称:NadekoBot,代码行数:8,代码来源:PermissionsHandler.cs


示例8: ValidateChannel

 internal static Channel ValidateChannel(Server server, string channelName) {
     if (string.IsNullOrWhiteSpace(channelName))
         throw new ArgumentNullException(nameof(channelName));
     var channel = server.FindChannels(channelName, ChannelType.Text).FirstOrDefault();
     if (channel == null)
         throw new NullReferenceException("That channel does not exist.");
     return channel;
 }
开发者ID:ZR2,项目名称:l,代码行数:8,代码来源:PermissionHelper.cs


示例9: Unban

		/// <summary> Unbans a user from the provided server. </summary>
		public async Task Unban(Server server, string userId)
		{
			if (server == null) throw new ArgumentNullException(nameof(server));
			if (userId == null) throw new ArgumentNullException(nameof(userId));
			CheckReady();

			try { await _api.UnbanUser(server.Id, userId).ConfigureAwait(false); }
			catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:10,代码来源:DiscordClient.Bans.cs


示例10: GetChannelPermissionsById

        internal static Permissions GetChannelPermissionsById(Server server, ulong id)
        {
            ServerPermissions serverPerms;
            if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
                return null;

            Permissions toReturn;
            serverPerms.ChannelPermissions.TryGetValue(id, out toReturn);
            return toReturn;
        }
开发者ID:Ryonez,项目名称:Lucy,代码行数:10,代码来源:PermissionsHandler.cs


示例11: ValidateRole

        internal static Role ValidateRole(Server server, string roleName) {
            if (string.IsNullOrWhiteSpace(roleName))
                throw new ArgumentNullException(nameof(roleName));

            if (roleName.Trim() == "everyone")
                roleName = "@everyone";
            var role = server.FindRoles(roleName).FirstOrDefault();
            if (role == null)
                throw new NullReferenceException("That role does not exist.");
            return role;
        }
开发者ID:ZR2,项目名称:l,代码行数:11,代码来源:PermissionHelper.cs


示例12: ChangeColor

        private async Task ChangeColor(Server s)
        {
            for(int i = 0; i < 100; i++)
            {
                Role role = s.GetUser(Disco.Bot.Client.CurrentUser.Id).Roles.FirstOrDefault();

                currentColor++;

                await role.Edit(null, null, _colors[currentColor % 15].Color);
                Thread.Sleep(100);
            }
        }
开发者ID:epicmiro,项目名称:DiscoBot,代码行数:12,代码来源:RainbowModule.cs


示例13: GetStatistics

 public Statistics GetStatistics(Server server)
 {
     return new Statistics
     {
         ServerName = server.Name,
         Owner = server.Owner,
         CreatedOn = server.Owner.JoinedAt,
         TotalMembers = server.Members.Count(),
         Karma = GetKarma(),
         Messages = GetMessages(server),
         Mentions = GetMentions(server)
     };
 }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:13,代码来源:StatsService.cs


示例14: GetInvites

		/// <summary> Gets all active (non-expired) invites to a provided server. </summary>
		public async Task<Invite[]> GetInvites(Server server)
		{
			if (server == null) throw new ArgumentNullException(nameof(server));
			CheckReady();

			var response = await _api.GetInvites(server.Id).ConfigureAwait(false);
			return response.Select(x =>
			{
				var invite = new Invite(this, x.Code, x.XkcdPass, x.Guild.Id, x.Inviter?.Id, x.Channel?.Id);
				invite.Cache(); //Builds references
				invite.Update(x);
				return invite;
			}).ToArray();
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:15,代码来源:DiscordClient.Invites.cs


示例15: AddEvent

        public void AddEvent(Server server, Channel channel, User user, EventType eventType)
        {
            var eventToSave = new Event
            {
                Id = Guid.NewGuid(),
                User = user,
                Server = server,
                Channel = channel,
                EventType = eventType,
                OccuredOn = DateTime.Now
            };

            _eventRepository.Insert(eventToSave);
        }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:14,代码来源:EventService.cs


示例16: MainAsync

        public static async Task MainAsync(Server server, Channel channel, User user, IEnumerable<string> args)
        {
            bool isError = false;
            string errorMessage = "";

            try
            {
                Color c = null;
                Role r = null;
                string colorName = null;

                if (args.FirstOrDefault() != null)
                    colorName = args.FirstOrDefault().ToLower();

                c = GetRoleColor(colorName);

                if (colorName != null && c != null)
                {

                    if ((r = GetRole(Capitalize(args.First().ToLower()), server.Roles)) != null)
                    {
                        await CheckForRolesAsync(user, server.Roles);
                        await user.AddRoles(r);
                    }
                    else
                    {
                        await CheckForRolesAsync(user, server.Roles);
                        string roleName = string.Format("{0}{1}", rolePrefix, Capitalize(colorName));
                        await user.AddRoles(await server.CreateRole(roleName, color: c));
                    }
                }
                else
                {
                    await channel.SendMessage(user.Mention + " Wrong colour input, check help for working colours.");
                }
            }
            catch (Exception ex)
            {
                isError = true;
                errorMessage = ex.Message.ToString();
            }

            if (isError)
                await channel.SendMessage(user.Mention + " " + errorMessage);

            await DeleteUnusedRolesAsync(server.Roles);
        }
开发者ID:XanderBras,项目名称:ColourBot,代码行数:47,代码来源:ColourCommand.cs


示例17: GetVoiceClient

		public IDiscordVoiceClient GetVoiceClient(Server server)
		{
			if (server.Id == null) throw new ArgumentNullException(nameof(server.Id));

			if (!Config.EnableVoiceMultiserver)
			{
				if (server.Id == _voiceServerId)
					return this;
				else
					return null;
			}

			DiscordWSClient client;
			if (_voiceClients.TryGetValue(server.Id, out client))
				return client;
			else
				return null;
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:18,代码来源:DiscordClient.Voice.cs


示例18: LeaveVoiceServer

		public async Task LeaveVoiceServer(Server server)
		{
			if (server == null) throw new ArgumentNullException(nameof(server));			

			if (Config.EnableVoiceMultiserver)
			{
				//client.CheckReady();
				DiscordWSClient client;
				if (_voiceClients.TryRemove(server.Id, out client))
					await client.Disconnect().ConfigureAwait(false);
			}
			else
			{
				CheckReady(checkVoice: true);
				await _voiceSocket.Disconnect().ConfigureAwait(false);
				_dataSocket.SendLeaveVoice(server.Id);
			}
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:18,代码来源:DiscordClient.Voice.cs


示例19: HelpAsync

        public static async Task HelpAsync(Server server, Channel channel, User user, IEnumerable<string> args)
        {
            bool isError = false;
            string errorMessage = "";

            try
            {
                Channel ch = await user.CreatePMChannel();
                await ch.SendMessage(WriteHelpMessage());
            }
            catch (Exception ex)
            {
                isError = true;
                errorMessage = ex.Message.ToString();
            }

            if (isError)
                await channel.SendMessage(user.Mention + " " + errorMessage);
        }
开发者ID:XanderBras,项目名称:ColourBot,代码行数:19,代码来源:ColourCommand.cs


示例20: CreateVoiceClient

		private async Task<IDiscordVoiceClient> CreateVoiceClient(Server server)
		{
			if (!Config.EnableVoiceMultiserver)
			{
				_voiceServerId = server.Id;
				return this;
			}

			var client = _voiceClients.GetOrAdd(server.Id, _ =>
			{
				var config = _config.Clone();
				config.LogLevel = _config.LogLevel;// (LogMessageSeverity)Math.Min((int)_config.LogLevel, (int)LogMessageSeverity.Warning);
				config.VoiceOnly = true;
				config.VoiceClientId = unchecked(++_nextVoiceClientId);
				return new DiscordWSClient(config, server.Id);
			});
			client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}");
			await client.Connect(_gateway, _token).ConfigureAwait(false);
			return client;
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:20,代码来源:DiscordClient.Voice.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Discord.User类代码示例发布时间:2022-05-24
下一篇:
C# Discord.DiscordClient类代码示例发布时间: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