Discord Raffle Bot for Discord Communities

in utopian-io •  6 months ago

discordraffle.PNG

Discord Raffle Bot

Repository

The Discord Raffle Bot is, as the name suggests, a simple python bot for hosting real time raffles for talk shows, communities, livestreams and others. This simple bot allows for flexibility while utilizing just a single command to ensure simplicity for non-tech savvy users.
People experienced in the Python programming language will also be able to easily expand on the bot, add new functionalities and commands thanks to an easy and simple code design that welcomes even the beginners (such as the command() function)

Technology Stack

This bot utilizes just Python 3.6 (should work on 3.0 and newer, but was tested on 3.6) and the discord.py Python library.

The bot is heavily dependent on the asyncio library (installed by default) which allows Python to act as an asynchronous programming language. This ensures that the bot can be run on multiple discord servers and in multiple channels at once without stopping raffles already taking place and without hosting multiple instances of the bot.

Customization for your server

All the messages sent by the bot can be found on line 7 in the r_messages dictionary. They can be edited with ease as long as variables are kept in order. If variables are to be changed, you'll need to replace the .format() method's argument where the message is used.

Permission to use the bot can be set to a role on line 17. It's also possible to change it to check for usernames instead by adjusting the permission_check() function on line 4 in the utils.py file.

Custom commands can be added by following the example of !raffle (line 29) in the command() function (line 23). They can be assigned for different lists of roles to allow more flexible permissions by smart utilization of the utils.permission_check() function.

Roadmap

The project is finished aside from final polish and addition of good suggestions. It will also remain maintained for bugs if any are found.

How to contribute?

If you wish to contribute to this project, please use the Github Issues or create Pull Requests directly. You can also contact me via comments under this post.

My GitHub Account

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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 ;)

·

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!

Thank you for the contribution. You have bot empire on Discord. :)

A couple of feedbacks:

Add roles with the permission to use the bot to line 18.

This is not a good practice for reusability. It would be good if you get this role group from a config file or a sys argument to the bot, or even from a environment variable. (Like how you do with RAFFLE_TOKEN.

Also, I see very long lines and non-standard indentation. I would strongly suggest following oeo8. It's pretty much an industry standard about how you style the python codes. (indentation 4 spaces instead of tabs, 80 char limit, etc.)

On last thing about the commit messages, we love descriptive commit messages at Utopian. Commit messages like "Update utils.py" doesn't mean much to the potential code/repository while "Add missing library import (random)" sounds like better. Here is a great guide about writing good commit messages.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

·

Thank you a lot! The editing at line 18 is indeed far from a perfect practice and I agree I should look into config files/ENV variables instead. I guess this is a better time for that than ever!

Thank you for letting me know about oeo8 as well. I'll spend some time today getting used to that as it'll surely improve the clarity and quality of my code.

Finally, the commit messages got a little messy when I tried to update the typos and simple mistakes, which shouldn't have happened. I tried to leave descriptive comments under them where applicable. That being said, thank you for the guidelines, I'll definitely check them out!

·

Hey @emrebeyler
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!

Hey @jestemkioskiem
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

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

Vote for Utopian Witness!

Congratulations @jestemkioskiem! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!