Exemplo n.º 1
0
        public async Task <Message> Reply(string text = null, Embed embed = null, AllowedMentions?mentions = null)
        {
            if (!BotPermissions.HasFlag(PermissionSet.SendMessages))
            {
                // Will be "swallowed" during the error handler anyway, this message is never shown.
                throw new PKError("PluralKit does not have permission to send messages in this channel.");
            }

            if (embed != null && !BotPermissions.HasFlag(PermissionSet.EmbedLinks))
            {
                throw new PKError("PluralKit does not have permission to send embeds in this channel. Please ensure I have the **Embed Links** permission enabled.");
            }

            var msg = await _rest.CreateMessage(_channel.Id, new MessageRequest
            {
                Content = text,
                Embed   = embed,
                // Default to an empty allowed mentions object instead of null (which means no mentions allowed)
                AllowedMentions = mentions ?? new AllowedMentions()
            });

            if (embed != null)
            {
                // Sensitive information that might want to be deleted by :x: reaction is typically in an embed format (member cards, for example)
                // This may need to be changed at some point but works well enough for now
                await _commandMessageService.RegisterMessage(msg.Id, Author.Id);
            }

            return(msg);
        }
Exemplo n.º 2
0
        public async Task <DiscordMessage> Reply(string text = null, DiscordEmbed embed = null, IEnumerable <IMention> mentions = null)
        {
            if (!this.BotHasAllPermissions(Permissions.SendMessages))
            {
                // Will be "swallowed" during the error handler anyway, this message is never shown.
                throw new PKError("PluralKit does not have permission to send messages in this channel.");
            }

            if (embed != null && !this.BotHasAllPermissions(Permissions.EmbedLinks))
            {
                throw new PKError("PluralKit does not have permission to send embeds in this channel. Please ensure I have the **Embed Links** permission enabled.");
            }
            var msg = await Channel.SendMessageFixedAsync(text, embed : embed, mentions : mentions);

            if (embed != null)
            {
                // Sensitive information that might want to be deleted by :x: reaction is typically in an embed format (member cards, for example)
                // This may need to be changed at some point but works well enough for now
                await _commandMessageService.RegisterMessage(msg.Id, Author.Id);
            }

            return(msg);
        }