Project Hazard is a Discord bot built using the discord.py library, offering a variety of functionalities, including command synchronization across different guilds and a coin-tossing command that combines random images. Below is an overview of the main components and functionalities of the code.
The sync
command is used to synchronize commands across guilds. The command can be executed with different specifications, such as syncing globally (~
), copying global commands to the current guild (*
), or clearing all commands in the current guild before syncing (^
). The command can also sync to specific guilds provided as arguments.
@commands.command()
@commands.guild_only()
@commands.is_owner()
async def sync(ctx: commands.Context, guilds: commands.Greedy[discord.Object], spec: Optional[Literal["~", "*", "^"]] = None) -> None:
# ... (implementation details)
The hazard
and hazard_red
commands allow users to toss a coin, combining multiple random images to create a visual representation of the coin toss. The Image
module from the PIL library is used to manipulate and combine images. The resulting image is saved, sent as a Discord file, and optionally removed after sending.
@client.tree.command(name="hazard", description="Toss a coin")
async def hazard(interaction: discord.Interaction):
# ... (implementation details)
@client.tree.command(name="hazard_red", description="Toss a coin")
async def hazard(interaction: discord.Interaction):
# ... (implementation details)
These commands utilize the get_random_images_from_folder
function to retrieve random image paths from specified folders. The combined image is created by horizontally pasting individual images, simulating a coin toss with unique visuals.