Added main.py with dice roll command function and changed .gitignore to not copy the config file with the Discord bot TOKEN #1
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
config.py
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
||||
48
main.py
Normal file
48
main.py
Normal 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)
|
||||
Loading…
x
Reference in New Issue
Block a user