예제 #1
0
        public static async Task <DiscordMessage> SendAsync(DiscordChannel channel, string textContent, DiscordEmbed embedContent = null)
        {
            try
            {
                if (!ChannelHasPermission(channel, Permissions.SendMessages))
                {
                    return(null);
                }

                if (embedContent == null)
                {
                    return(await channel.SendMessageAsync(textContent, false));
                }
                else
                {
                    // Either make sure we have permission to use embeds or convert the embed to text
                    if (ChannelHasPermission(channel, Permissions.EmbedLinks))
                    {
                        return(await channel.SendMessageAsync(textContent, false, embedContent));
                    }
                    else
                    {
                        return(await channel.SendMessageAsync(MessageBuilder.EmbedToText(textContent, embedContent)));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error occurred while attempting to send Discord message. Error message: " + e);
                return(null);
            }
        }
예제 #2
0
        public static async Task <DiscordMessage> ModifyAsync(DiscordMessage message, string textContent, DiscordEmbed embedContent = null)
        {
            try
            {
                if (!ChannelHasPermission(message.Channel, Permissions.ManageMessages))
                {
                    return(null);
                }

                if (embedContent == null)
                {
                    return(await message.ModifyAsync(textContent));
                }
                else
                {
                    // Either make sure we have permission to use embeds or convert the embed to text
                    if (ChannelHasPermission(message.Channel, Permissions.EmbedLinks))
                    {
                        return(await message.ModifyAsync(textContent, embedContent));
                    }
                    else
                    {
                        await message.ModifyEmbedSuppressionAsync(true); // Remove existing embeds

                        return(await message.ModifyAsync(MessageBuilder.EmbedToText(textContent, embedContent)));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error occurred while attempting to modify Discord message. Error message: " + e);
                return(null);
            }
        }
예제 #3
0
 private async Task RespondToCommand(CommandContext ctx, string textContent, DiscordEmbed embedContent = null)
 {
     try
     {
         if (embedContent == null)
         {
             await ctx.RespondAsync(textContent, false);
         }
         else
         {
             // Either make sure we have permission to use embeds or convert the embed to text
             if (DiscordUtil.ChannelHasPermission(ctx.Channel, Permissions.EmbedLinks))
             {
                 await ctx.RespondAsync(textContent, false, embedContent);
             }
             else
             {
                 await ctx.RespondAsync(MessageBuilder.EmbedToText(textContent, embedContent), false);
             }
         }
     }
     catch (Exception e)
     {
         LogCommandException(e);
     }
 }