Skip to content

Instantly share code, notes, and snippets.

@cibere
Created March 6, 2023 02:06
Show Gist options
  • Save cibere/06de7dca5a0231e17f0560dd75a3b714 to your computer and use it in GitHub Desktop.
Save cibere/06de7dca5a0231e17f0560dd75a3b714 to your computer and use it in GitHub Desktop.
import discord
import random
intents = discord.Intents.default()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user.name} (ID: {client.user.id})')
@client.event
async def on_message(message):
if message.guild.id == (server id) and message.channel.id == (channel id):
if message.author == client.user:
return
def roll_dice(dice_type, quantity=1):
rolls = [random.randint(1, dice_type) for _ in range(quantity)]
return rolls
while True:
command = input("Enter command (roll [d100, d20, d12, d10, d6, d4]): ")
command_parts = command.split(" ")
if len(command_parts) != 2 or command_parts[0] != "roll":
print("Invalid command")
continue
dice_notation = command_parts[1]
if 'd' not in dice_notation:
print("Invalid dice notation")
continue
quantity, dice_type = dice_notation.split('d')
if quantity == '':
quantity = 1
else:
quantity = int(quantity)
dice_type = int(dice_type)
if dice_type == 100:
result = roll_dice(100, quantity)
elif dice_type == 20:
result = roll_dice(20, quantity)
elif dice_type == 12:
result = roll_dice(12, quantity)
elif dice_type == 10:
result = roll_dice(10, quantity)
elif dice_type == 6:
result = roll_dice(6, quantity)
elif dice_type == 4:
result = roll_dice(4, quantity)
else:
print("Invalid dice type")
continue
if quantity > 1:
print(f"Results for {quantity}d{dice_type}: {result}")
else:
print(f"Result for 1d{dice_type}: {result[0]}")
client.run(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment