Created
July 2, 2025 21:34
-
-
Save bferguson3/657dca5eca0f3e5e8793f25ddf7922c9 to your computer and use it in GitHub Desktop.
A simple Sword World dice bot for Discord with support for strike rolls 0-100
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sword World dice bot | |
# | |
# commands: !h[elp], !r[oll], !s[trike] | |
# | |
# (c)2025 bferguson3 @ github | |
import discord,os,random,re | |
intents = discord.Intents.all() | |
client = discord.Client(command_prefix="!", intents=intents) | |
strike_table=[ | |
[0,0,0,1,2,2,3,3,4,4], | |
[0,0,0,1,2,2,3,3,4,4], | |
[0,0,0,1,2,3,4,4,4,4], | |
[0,0,1,1,2,3,4,4,4,5], | |
[0,0,1,2,2,3,4,4,5,5], | |
[0,1,1,2,2,3,4,5,5,5], | |
[0,1,1,2,3,3,4,5,5,5], | |
[0,1,1,2,3,4,4,5,5,6], | |
[0,1,2,2,3,4,4,5,6,6], | |
[0,1,2,3,3,4,4,5,6,7], | |
[1,1,2,3,3,4,5,5,6,7], | |
[1,2,2,3,3,4,5,6,6,7], | |
[1,2,2,3,4,4,5,6,6,7], | |
[1,2,3,3,4,4,5,6,7,7], | |
[1,2,3,4,4,4,5,6,7,8], | |
[1,2,3,4,4,5,5,6,7,8], | |
[1,2,3,4,4,5,6,7,7,8], | |
[1,2,3,4,5,5,6,7,7,8], | |
[1,2,3,4,5,6,6,7,7,8], | |
[1,2,3,4,5,6,7,7,8,9], | |
[1,2,3,4,5,6,7,8,9,10], | |
[1,2,3,4,6,6,7,8,9,10], | |
[1,2,3,5,6,6,7,8,9,10], | |
[2,2,3,5,6,7,7,8,9,10], | |
[2,3,4,5,6,7,7,8,9,10], | |
[2,3,4,5,6,7,8,8,9,10], | |
[2,3,4,5,6,8,8,9,9,10], | |
[2,3,4,6,6,8,8,9,9,10], | |
[2,3,4,6,6,8,9,9,10,10], | |
[2,3,4,6,7,8,9,9,10,10], | |
[2,4,4,6,7,8,9,10,10,10], | |
[2,4,5,6,7,8,9,10,10,11], | |
[3,4,5,6,7,8,10,10,10,11], | |
[3,4,5,6,8,8,10,10,10,11], | |
[3,4,5,6,8,9,10,10,11,11], | |
[3,4,5,7,8,9,10,10,11,12], | |
[3,5,5,7,8,9,10,11,11,12], | |
[3,5,6,7,8,9,10,11,12,12], | |
[3,5,6,7,8,10,10,11,12,13], | |
[4,5,6,7,8,10,11,11,12,13], | |
[4,5,6,7,9,10,11,11,12,13], | |
[4,6,6,7,9,10,11,12,12,13], | |
[4,6,7,7,9,10,11,12,13,13], | |
[4,6,7,8,9,10,11,12,13,14], | |
[4,6,7,8,10,10,11,12,13,14], | |
[4,6,7,9,10,10,11,12,13,14], | |
[4,6,7,9,10,10,12,13,13,14], | |
[4,6,7,9,10,11,12,13,13,15], | |
[4,6,7,9,10,12,12,13,13,15], | |
[4,6,7,10,10,12,12,13,14,15], | |
[4,6,8,10,10,12,12,13,15,15], | |
[5,7,8,10,10,12,12,13,15,15], | |
[5,7,8,10,11,12,12,13,15,15], | |
[5,7,9,10,11,12,12,14,15,15], | |
[5,7,9,10,11,12,13,14,15,16], | |
[5,7,10,10,11,12,13,14,16,16], | |
[5,8,10,10,11,12,13,15,16,16], | |
[5,8,10,11,11,12,13,15,16,17], | |
[5,8,10,11,12,12,13,15,16,17], | |
[5,9,10,11,12,12,14,15,16,17], | |
[5,9,10,11,12,13,14,15,16,18], | |
[5,9,10,11,12,13,14,16,17,18], | |
[5,9,10,11,13,13,14,16,17,18], | |
[5,9,10,11,13,13,15,17,17,18], | |
[5,9,10,11,13,14,15,17,17,18], | |
[5,9,10,12,13,14,15,17,18,18], | |
[5,9,10,12,13,15,15,17,18,19], | |
[5,9,10,12,13,15,16,17,19,19], | |
[5,9,10,12,14,15,16,17,19,19], | |
[5,9,10,12,14,16,16,17,19,19], | |
[5,9,10,12,14,16,17,18,19,19], | |
[5,9,10,13,14,16,17,18,19,20], | |
[5,9,10,13,15,16,17,18,19,20], | |
[5,9,10,13,15,16,17,19,20,21], | |
[6,9,10,13,15,16,18,19,20,21], | |
[6,9,10,13,16,16,18,19,20,21], | |
[6,9,10,13,16,17,18,19,20,21], | |
[6,9,10,13,16,17,18,20,21,22], | |
[6,9,10,13,16,17,19,20,22,23], | |
[6,9,10,13,16,18,19,20,22,23], | |
[6,9,10,13,16,18,20,21,22,23], | |
[6,9,10,13,17,18,20,21,22,23], | |
[6,9,10,14,17,18,20,21,23,24], | |
[6,9,11,14,17,18,20,21,23,24], | |
[6,9,11,14,17,19,20,21,23,24], | |
[6,9,11,14,17,19,21,22,23,24], | |
[7,10,11,14,17,19,21,22,23,25], | |
[7,10,12,14,17,19,21,22,24,25], | |
[7,10,12,14,18,19,21,22,24,25], | |
[7,10,12,15,18,19,21,22,24,26], | |
[7,10,12,15,18,19,21,23,25,26], | |
[7,11,13,15,18,19,21,23,25,26], | |
[7,11,13,15,18,20,21,23,25,27], | |
[8,11,13,15,18,20,22,23,25,27], | |
[8,11,13,16,18,20,22,23,25,28], | |
[8,11,14,16,18,20,22,23,26,28], | |
[8,11,14,16,19,20,22,23,26,28], | |
[8,12,14,16,19,20,22,24,26,28], | |
[8,12,15,16,19,20,22,24,27,28], | |
[8,12,15,17,19,20,22,24,27,29], | |
[8,12,15,18,19,20,22,24,27,30] | |
] | |
@client.event | |
async def on_ready(): | |
print("We have logged in as {0.user}".format(client)) | |
@client.event | |
async def on_message(message): | |
if message.author == client.user: | |
return | |
if message.content.lower().startswith("!r"): | |
try: | |
if message.content.lower().find("d") != -1: | |
die = message.content.lower().split("d")[0] | |
n = len(die)-1 | |
try: | |
while int(die[n]): | |
n -= 1 | |
except: | |
pass | |
mod = 0 | |
if message.content.find("+") != -1: | |
mod = int(message.content.split("+")[1]) | |
if message.content.find("-") != -1: | |
mod = int(message.content.split("-")[1]) * -1 | |
die = int(die[n:]) | |
roll = [] | |
tot = 0 | |
while die > 0: | |
roll.append(random.randint(1, 6)) | |
tot += roll[len(roll)-1] | |
die -= 1 | |
msg = "Result: " + str(tot + mod) + " (" | |
for r in roll: | |
msg += str(r) + ", " | |
msg = msg[:len(msg)-2] | |
msg += " + " + str(mod) + ")" | |
await message.channel.send(msg) | |
else: | |
await message.channel.send("Use dice format: xd+n") | |
except: | |
await message.channel.send("Use dice format: xd+n") | |
elif message.content.lower().startswith("!s"): | |
try: | |
sp = int(re.sub('\\D','',message.content.lower())) | |
roll = random.randint(1, 6) | |
roll += random.randint(1, 6) | |
roll -= 3 # range of 0-9 | |
if roll == -1: | |
await message.channel.send("Miss!! (Auto-fail)") | |
else: | |
v = strike_table[sp][roll] | |
await message.channel.send("Damage: " + str(v) + " (rolled " + str(roll+3) + ")") | |
except: | |
await message.channel.send("Not a valid number?") | |
elif message.content.lower().startswith("!h"): | |
await message.channel.send("To use:\n!r or !roll *x*d+*n* to roll dice\n!s or !strike *n* to do a strike check\n!h or !help to see this text\n") | |
f = open("discord_bot_key.txt", "r") | |
key = f.read() | |
f.close() | |
client.run(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment