DiscordPHP icon indicating copy to clipboard operation
DiscordPHP copied to clipboard

Poll permissions, events, and other related changes

Open valzargaming opened this issue 1 year ago • 4 comments

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

valzargaming avatar May 10 '24 17:05 valzargaming

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

valzargaming avatar May 10 '24 18:05 valzargaming

~~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) {
    //
});

Log1x avatar Jul 18 '24 21:07 Log1x

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

valzargaming avatar Jul 18 '24 21:07 valzargaming

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

valzargaming avatar Aug 13 '24 05:08 valzargaming