discord-php / DiscordPHP

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

Fix variable becomes undefined in Event handler codes #1013

Closed SQKo closed 1 year ago

SQKo commented 1 year ago

Reported by Discord Member Tady#5553

Undefined variable $channel in /root/test/vendor/team-reflex/discord-php/src/Discord/WebSockets/Events/MessageCreate.php on line 72

While these code seems fine (even the syntax is OK and no compile error), for unknown reasons sometimes they are being undefined. I suspect it has something to do with the react/async coroutines yield when the variable is prepared in the if condition scope like that, does not guarantee it to be set outside the scope.

So I added isset() as a safe workaround.

Tested.