discord-php / DiscordPHP

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

Poll permissions, events, and other related changes #1226

Closed valzargaming closed 1 week ago

valzargaming commented 4 months ago

@see https://github.com/discord/discord-api-docs/pull/6746/files

valzargaming commented 4 months ago

I'm running out of time to be able to work on this, if someone can please finish this up.

Log1x commented 2 months ago

This should be about ready once https://github.com/discord-php/DiscordPHP-Http/pull/28 is merged.

The only thing I was unsure of is the namespace for the poll create request part. I feel like it should still be named Poll so I put it in its own Request namespace similar to interactions.

Example usage:

use Discord\Builders\MessageBuilder;
use Discord\Parts\Channel\Poll\Poll;

$message = MessageBuilder::new();

$poll = new Poll($this->discord());

$poll = $poll
    ->setQuestion('What is your favorite color?')
    ->setAnswers(['Red', 'Green', 'Blue'])
    ->setDuration(1)
    ->setAllowMultiselect(true);

$message->setPoll($poll);

$channel->sendMessage($message);

Screenshot

$discord->on(Event::MESSAGE_POLL_VOTE_ADD, function (PollAnswer $answer, Discord $discord) {
    //
});

$discord->on(Event::MESSAGE_POLL_VOTE_REMOVE, function (PollAnswer $answer, Discord $discord) {
    //
});
valzargaming commented 2 months ago

Codacy jank can be ignored here, formatting is the same as the rest of the lib. This looks good to me.

valzargaming commented 1 month ago

Codacy is just complaining about a variable named $id being too short and can be safely ignored