You are viewing a single comment's thread from:

RE: Discord Raffle Bot for Discord Communities

in #utopian-io7 years ago

If this is Raffle known from Twitch then it is nice idea for a Discord bot!

I have some piece of advice into the code. The random.randint(a, b) return a random integer N such that a <= N <= b. The participants_number should be added by -1 then because we start count from 0. This is crucial part in Raffle functionality and here I see it mistaken by off by one error.

def pick_ticket(participants):
    participants_number = len(participants)
    ticket = random.randint(0,participants_number)
    winner = participants[ticket]

https://github.com/Jestemkioskiem/discord-raffle-bot/blob/master/raffle_bot/utils.py#L17

There is also specific scenario, when literally nobody takes part into Raffle. participants array is empty then. The best would be to check if the array length is non-zero.

Beside that good job ;)

Sort:  

Hey! Thank you for the reports. These two should absolutely be fixed and I'll push the changes right now!

The raffle works similarly to the one from Twitch, although it doesn't currently allow for a re-roll. It does send a DM to the raffle starter with all IDs of the participants to allow for a manual re-roll though if the winner is inactive, for example.

The bot was inspired by @buckydurddle who wants to have raffles on his radio shows!


Hey @mys Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

Contributing on Utopian
Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!