Added main.py with dice roll command function and changed .gitignore to not copy the config file with the Discord bot TOKEN #1

Merged
enub merged 1 commits from addBasicFiles into main 2025-02-02 18:21:30 +01:00
2 changed files with 50 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
config.py
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/

48
main.py Normal file
View File

@ -0,0 +1,48 @@
from random import randint
import discord
from discord import app_commands
import config
discord_bot_token = config.TOKEN
intents = discord.Intents.all()
bot_client = discord.Client(intents=intents)
tree = app_commands.CommandTree(bot_client)
"""
My Bots Overview:
https://discordapp.com/developers/applications
Discord Developer Portal:
https://discordapp.com/developers/docs/resources/channel
Discord Bot API Documentation:
https://discordpy.readthedocs.io/en/latest/api.html
Changelog:
https://discordpy.readthedocs.io/en/latest/whats_new.html
"""
@bot_client.event
async def on_ready():
print("Discord.py version {}\n".format(discord.__version__))
await tree.sync()
@tree.command(name="roll", description="rolles Dice")
async def __command_roll(interaction: discord.Interaction, amount: int, dice_size: int):
try:
rolles = [randint(1, int(dice_size)) for _ in range(int(amount))]
embed = discord.Embed(color=randint(0, 0xFFFFFF))
embed.add_field(name="Rolles", value=str(rolles), inline=False)
embed.add_field(name="Sum", value=sum(rolles), inline=False)
await interaction.response.send_message(embed=embed, ephemeral=True)
except Exception as e:
await interaction.response.send_message(content=f"Error: {e}", ephemeral=True)
###
# Start Bot
###
bot_client.run(discord_bot_token)