Back to All Posts

ArtScuffle (Pt 1)

Originally posted on 2023-07-06

With it being Artfight this month, the Beantown crew decided to do a mini version of the game in the server. The main event can be a bit... scary... so it was nice to be able to host a smaller version within just friends. Since it was a Discord server event, I decided to make a Discord bot to help us log our attacks. I'll also be building a small website so people can view all the cool stuff that gets made this month... but that'll be covered in a later post.

It's been a while since I've created a Discord bot, but luckily I still had the frame of some of my old bots. Although... with the introduction of slash commands (yes, yes, I know that was forever ago), it has been a challenge to get discord.py to work how I want it to. Even though Carter suggested Rust or Go, I'm a woman set in my ways and I was determined to get the Python library working.

Select Menus

I'm still unsure if the way I approached the select menus was the best way to handle what I wanted to do. It was a lot of back and forth in terms of figuring out how to get it to work... and unfortunately, I didn't make this a git project until way too late into development so I do not have a good record of all my attempts. Here's a general gist of stuff I've tried:

  1. Having multiple selects all at once

This did not work. Discord has a limit on the number of "rows" an interaction can have and, unfortunately, I had 5 selects. While this would've been perfect for the 5 limit... I also needed a "I'm finished!" button so users could go back and change things if they made a mistake.

  1. Editing the message to change to the next option

I could not figure this out, but while attempting to do this, I came across the "solution".

  1. After each option is selected, a new message is sent with the next step

This is what the bot currently does! It's a little bit janky... but it works.

Select Menus... continued

However, I soon realized that this STILL wasn't ideal because users could change their choice even after the next option menu was presented. For some reason, setting the selects to "disabled" was not possible after their creation so I was stumped. I think I'm missing something to truly update the message to disabled as well, but after reading the discord.py docs for hours (okay maybe it was just one hour), I decided to try another approach.

It's not the cleanest code, but after pressing the "I'm Finished!" button, all of the messages (which are saved in a view variable... also not super clean) get deleted. To go around the timeout, there's a slight lag between each getting deleted. Theoretically, a user could mess with the points and maybe break the database if they have quick fingers, but right now, it is a solution that works. I'll probably come back to find a real solution to this later.

Here's some fun screenshots from my test bot!

Minor Database Things

It was pretty easy to add stuff to the database using mysql-connector-python so I won't write too much on that. When I put together the README.md for this project, I'll probably add a folder to the repo with the SQL files for creating the necessary tables. I considered adding some Stored Procedures too (haha you can see the Internship affecting me), but I don't think they're quite necessary for such a small project... we'll see though if I have to do some complicated point mathematics for future commands.