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


C# Discord.Server类代码示例

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


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


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