Bot to perform Instant-runoff voting on Discord.
Made using the amazing discord.py
Forgive me for the spaghetti code.
Any suggestions, questions, or anything else? Feel free to contact me, I'm lonely.
Contact me on Discord: @PixeledBrain#0070 or by email: [email protected]
To invite my instance of this bot, use this link:
https://discord.com/oauth2/authorize?client_id=830927490482569217&permissions=347200&scope=bot
It will probably be offline though, if you want to use it, feel free to poke me on Discord @PixeledBrain#0070
I used version 3.9.4, so I recommend using that one for less issues. Download here.
then run the command on cmd:
py -3 -m pip install -U discord.py
to install discord.py
(If that doesn't work, check out their installation guide)
Alternatively, you can use docker. A simple compose file is included.
- Create one at the Discord developer website
- Click on New Application, give it a name (this is not the user name for the bot)
- Click on the
Bottab on the left. - Add a bot, give it a name.
- Copy the bot's token, replace "TOKENHERE" in "runBot.bat" with the token
To invite that bot to a server, you need an invite link.
- Go over to the
OAuth2tab in your application's page. - Tick
botin thescopescategory. - On the
Privileged Gateway Intents, add all 3 intents (im too lazy to give them one by one) - On the
permissionscategory, tick the following:- View Channels
- Send Messages
- Embed Links
- Read Message History
- Use External Emojis
- Add Reactions
- Manage messages
- Copy the link at the bottom of the
scopessection.
That link will be used to invite the bot to different servers.
Its easier to run with docker compose, to do so, simply copy .env.example to .env and replace the token value with your bot token. Then run docker compose up --build -d
To close it, run docker compose down
If you're on windows, you can just run the "runBot.bat" file to run the bot (assuming the correct token has been placed in the file, as described in the section above)
You can also run the bot directly from the command line by running the command:
python main.py TOKEN
Replacing TOKEN with your bot's token.
Ctrl+C on your keyboard with the CMD window focused should close the bot. Closing the whole CMD window will probably work too.
After having done set up the bot, and have it in a server, while online, an example use case could be the following:
- Copy the role ID for whatever role you want to make the bot administrator role, people with this role will be able to manage elections.
- Send a message on Discord with
!startUp ROLEID, replacing "ROLEID" with the role id you copied earlier. - To create an election, run
!createElection option1,option2,option3. You can replace the options, or add and remove more. - Copy the command example the bot provides, and on each line, replace "x" with your desired preference. You can remove lines for votes you dont want to make.
- Once everyone has voted, run
!electionWinnerto get a result. This gets rid of the election. - Go back to step 3 if you want to set up another one.
Default prefix: !
Note that commands are not case-sensitive, but any parameters are.
Notes:
<VAR> - means VAR is obligatory
[VAR] - means VAR is optional
Al AdminRole permissions can also be run by users with a role that gives them the "Administrator" permission on Discord.
| Command | Description | Permissions | Example |
|---|---|---|---|
startUp <AdminRole id> [new Prefix] |
Creates server data. Sets bot AdminRole (need to provide role ID, not name), and optionally, a new prefix. |
Discord "Administrator" Permission | !startUp 556940676495835146 $ |
exit |
Removes any stored server data. | AdminRole | !exit |
createElection <c1>,<c2>[, ...] |
creates an election with the given candidates, and prints out a nice copy-pasteable vote message. Opens the voting. | AdminRole | !createElection candidate1,candidate2,candidate3 |
closeElection |
Makes people unable to vote. | AdminRole | !closeElection |
openElection |
Makes peolpe able to vote (if it was closed manually). | AdminRole | !openElection |
electionWinner |
Calculates the election's winner, and removes the current vote. | AdminRole | !electionWinner |
vote <c1>:<pr1> [c2>:<pr2 ...] |
Registers a vote. preference values should be thought of as "1st option" for value 1, "2nd option" for value 2... Not all candidates need a vote. If a person casts more than one vote, their previous one is deleted. |
Anyone | - |
removeVote |
Removes the caller's vote | Anyone | !removeVote |
prefix <newPrefix> |
Changes command prefix to given one. | AdminRole | !prefix $ |
help or contact |
Sends a message with my Discord name for contact PixeledBrain#0070. |
Anyone | !help |
invite |
Invite link for my bot using this. (you can modify the link to yours in botClient.py). | Anyone | !invite |
github |
Links this page. | Anyone | !github |
commands |
Lists commands... kinda :P | Anyone | !commands |
- Make it so that each person can only vote once per vote
- Make it so that people can modify their vote if they recast it
- Invite command so people can invite the bot to a server
- Contact command
- GitHub command
- Add a "commands" command
- Command aliases
- Save status every so often
- Load from previous status
- Remove echo command
- Make an actual
commandscommand - Refactor (difference between vote and election)
- Add use instructions
- Change readme commands section to a table.
- Put each component into its own folder.
- Make it so Administration role can do all commands too (change isAdmin function) (In case wrong role id is provided)
- Flake8 compliant
- Remove vote command
- Show vote results
- Custom command aliases per server
- Make it pretty
- Send channel id for vote collection
- Private voting? dm?
- Multiple elections per server simultaneously (with name ids?)
- Make AdminRole optional?
- Fix up code for bot class.