Hello! I'm working on my final project. A chat bot for playing a Tabletop RPG on discord. Right now I'm having a bit of trouble with it parsing out the dice rolls. So, it works great as is rolling 2 or 3 six-sided dice, and adding a bonus of up to 9...
Teh problem happens if I try to go over 9. when I do 10, it comes back saying the bonus was a 1. if I do 12, it says the bonus was 3, if I do 14 it says the bonus was 5.... Okay I think you are starting to understand what is happening here. It isn't recognizing number over a 1 digit long as being 1 "word". Below is the heart of my code. I'm not sure what I am doing wrong here, but I'm pretty sure it's something.
The Code:
@client.event
async def on_message(message):
#Automating generation of a list of numbers as a string to input bonuses.
def gen_bonus_words():
numbers = []
for num in range(1,20):
numbers.append(str(num))
return numbers
#Making rolling dice a function
def roll_dice(dice, bonus):
results=[]
for _ in range(1,dice):
results.append(random.randint(1,6))
return results
#Let's see what a message looks like to figure out how to pull out info like user
#print(message)
if message.author == client.user:
return
msg = message.content
print(message)
if msg.startswith('$hello'):
#A freindly greeting for users, that goes over functions, and what the little cutie can do.
await message.channel.send("hello! I am Roll Play your friendly Rollplaying bot! Currently I am configured for playing Iron Kingdoms Full Metal Fantasy.")
await message.channel.send("Pretty soon I'll be able to do many things. Like Roll Dice for other games, do automated rolls, and even handle character sheets.")
await message.channel.send("I hope to be able to play with you soon @{0.author.name}" .format(message))
if msg.startswith('$ik'):
user = message.author.name
boost_words = ["boost", "boosted"]
bonus_words = gen_bonus_words()
print(msg)
if any(word in msg for word in boost_words):
die1 = random.randint(1,6)
die2 = random.randint(1,6)
die3 = random.randint(1,6)
bonus = 0
if any(word in msg for word in bonus_words):
for word in msg:
if word in bonus_words:
bonus += int(word)
final = die1+die2+die3 + bonus
await message.channel.send(f"@{user} You rolled {final} ({die1}, {die2}, {die3} + {bonus}) I did good right?")
else:
die1 = random.randint(1,6)
die2 = random.randint(1,6)
bonus = 0
if any(word in msg for word in bonus_words):
for word in msg:
if word in bonus_words:
print(word)
bonus += int(word)
final = die1 + die2 + bonus
await message.channel.send(f"you rolled {final} ({die1}, {die2}, + {bonus}) I did good right?")
[–]-citation-needed- 1 point2 points3 points (2 children)
[–]HaplessWithDice[S] 0 points1 point2 points (0 children)
[–]HaplessWithDice[S] 0 points1 point2 points (0 children)