discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
985 stars 236 forks source link

Embed not working #1035

Closed MattMski closed 1 year ago

MattMski commented 1 year ago

Environment

Describe the bug Hello, for some reason I noticed that all my embed commands on my bot stopped working. Not sure if something is broken but I am unable to send any embeds. I know I didn't change anything

To Reproduce Steps to reproduce the behavior:

1. Create embed
2. Send embed message

Expected behavior A embed being displayed on Discord

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

b3r3nd commented 1 year ago

@MattMski

Not sure if you are trying to fix it or not. But it must be changed in the DiscordPHP Lib.

There is a function called setFooter() in de Embed class, this function accepts the second parameter as icon URL. If none is given its sets the value to an empty string, which now is broken because it needs to be set to an actual NULL value. I am not entirely sure what the best solution might be, for me I fixed it now changing the required string type and setting a default NULL value.

Old function:

    public function setFooter(string $text, string $iconurl = ''): self
    {
        if (poly_strlen($text) === 0) {
            $this->footer = null;
        } elseif (poly_strlen($text) > 2048) {
            throw new \LengthException('Footer text can not be longer than 2048 characters.');
        } elseif ($this->exceedsOverallLimit(poly_strlen($text))) {
            throw new \LengthException('Embed text values collectively can not exceed than 6000 characters');
        } else {
            $this->footer = [
                'text' => $text,
                'icon_url' => $iconurl,
            ];
        }

        return $this;
    }

New functions which works for me:

    public function setFooter(string $text, string|null $iconurl = null): self
    {
        if (poly_strlen($text) === 0) {
            $this->footer = null;
        } elseif (poly_strlen($text) > 2048) {
            throw new \LengthException('Footer text can not be longer than 2048 characters.');
        } elseif ($this->exceedsOverallLimit(poly_strlen($text))) {
            throw new \LengthException('Embed text values collectively can not exceed than 6000 characters');
        } else {
            $this->footer = [
                'text' => $text,
                'icon_url' => $iconurl,
            ];
        }

        return $this;
    }

But now I am changing the vendor code locally which is nasty and only TMP fix. So something like this should be changed in the lib.

PeanutNL commented 1 year ago

We should also check the URL on the setImage and setThumbnail functions

b3r3nd commented 1 year ago

We should also check the URL on the setImage and setThumbnail functions

Not sure if that matters, at least I do not encounter any issues there but who knows..

MattMski commented 1 year ago

@MattMski

Not sure if you are trying to fix it or not. But it must be changed in the DiscordPHP Lib.

There is a function called setFooter() in de Embed class, this function accepts the second parameter as icon URL. If none is given its sets the value to an empty string, which now is broken because it needs to be set to an actual NULL value. I am not entirely sure what the best solution might be, for me I fixed it now changing the required string type and setting a default NULL value.

hey @b3r3nd appreciate the quick response and fix. Glad to see something pushed out soon as well.

Getting an error PHP Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE)

is this a PHP 8 only fix?

Edit: fixed by switching string|null to string

b3r3nd commented 1 year ago

@MattMski Not sure if you are trying to fix it or not. But it must be changed in the DiscordPHP Lib. There is a function called setFooter() in de Embed class, this function accepts the second parameter as icon URL. If none is given its sets the value to an empty string, which now is broken because it needs to be set to an actual NULL value. I am not entirely sure what the best solution might be, for me I fixed it now changing the required string type and setting a default NULL value.

hey @b3r3nd appreciate the quick response and fix. Glad to see something pushed out soon as well.

Getting an error PHP Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE)

is this a PHP 8 only fix?

Edit: fixed by switching string|null to string

Yes it was for php 8.0, but a fix has already been merged so if you pull issue should be resolved.

MattMski commented 1 year ago

Yes it was for php 8.0, but a fix has already been merged so if you pull issue should be resolved.

Worked for me, thanks @b3r3nd