SinisterRectus / Discordia

Discord API library written in Lua for the Luvit runtime environment
MIT License
697 stars 143 forks source link

Embeds broken for user bots #338

Closed JaceDoile closed 2 years ago

JaceDoile commented 2 years ago

I guess discord updated something recently and that broke Embeds for user bots (selfbots), i had made a custom embed wrapper but that isn't the issue as it works on normal bots

embed wrapper for anyone that wants it lol

local Embed                 = {};
Embed.__index               = Embed;

-- // Functions
function Embed.new()
    local self              = setmetatable({}, Embed);
    self.ConstructedEmbed   = {};
    return self, self.ConstructedEmbed;
end;

function Embed:setTitle(str)
    self.ConstructedEmbed.title = tostring(str) or "Drexcent's Emebed Wrapper";
end;

function Embed:setColor(hexColor)
    self.ConstructedEmbed.color = hexColor or 0xff5100;
end;

function Embed:setDescription(str)
    self.ConstructedEmbed.description = str;
end;

function Embed:setFooter(str, url)
    self.ConstructedEmbed.footer = {text = str or 'Drexcent\'s Embed Wrapper', icon_url = url or ""};
end;

function Embed:setURL(url)
    self.ConstructedEmbed.url = url or "";
end;

function Embed:setAuthor(str, logourl, url)
    self.ConstructedEmbed.author = {name = str or "", icon_url = logourl or "", url = url or ""};
end;

function Embed:setThumbnail(url)
    self.ConstructedEmbed.thumbnail = {url = url or ""};
end;

function Embed:setImage(url)
    self.ConstructedEmbed.image = {url = url or ""};
end;

function Embed:setTimestamp(time)
    self.ConstructedEmbed.timestamp = time or tostring(os.date("%I:%M"));
end;

function Embed:addField(fieldTitle, fieldValue, isFieldInline)
    if (self.ConstructedEmbed.fields) then
        table.insert(self.ConstructedEmbed.fields, {name = fieldTitle or "", value = fieldValue or "", inline = isFieldInline or true})
    else
        self.ConstructedEmbed.fields = {};
        table.insert(self.ConstructedEmbed.fields, {name = fieldTitle or "", value = fieldValue or "", inline = isFieldInline or true})
    end;
end;

function Embed:addFields(...)
    local fieldsIg = {...};
    if (self.ConstructedEmbed.fields) then
        for _, v in next, fieldsIg do
            if (type(v) == 'table') then
                table.insert(self.ConstructedEmbed.fields, v)
            end;
        end;
    else
        self.ConstructedEmbed.fields = {};
        for _, v in next, fieldsIg do
            if (type(v) == 'table') then
                table.insert(self.ConstructedEmbed.fields, v)
            end;
        end;
    end;
end;

return Embed;

note i may have done this incorrectly (im not really sure of myself lol) but please correct me if so, also heres an example for using it

local Embed = require('./EmbedWrapper');
local a, b = Embed.new();
a:setTitle('Oh look, a custom embed wrapper!!')
a:setDescription('i guess its sorta cool :)')
channel:send({embed = b})

But yeah if you're able to fix the embeds with discord that would be awesome!

JaceDoile commented 2 years ago

Apologies for the weird Indentations and the random missing ';' and stuff xD still works without them though just a cosmetic thing :)

SinisterRectus commented 2 years ago

I guess discord updated something recently and that broke Embeds for user bots (selfbots)