I am trying to accomplish a simple D6 dice rolling bot using this block of code
import discord
import random
# simplified numbers for testing critical misses/hits
DND_1d6 = [1, 6]
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith(";hello"):
await message.channel.send("Hello!")
# if the message starts with ;roll 1d6
if message.content.startswith(";roll 1d6"):
# we want to randomize the response from our numbers in DND_1d6
response = random.choice(DND_1d6)
# then we need to format this in a string
response_str = "You rolled {0}".format(response)
# the bot will send the message
await message.channel.send(response_str)
if message.content.startswith(";roll 2d6"):
response = random.choice(DND_1d6), random.choice(DND_1d6)
response_str = "You rolled {0} and {1} for a total of {2}".format(response[0], response[1], sum(response))
if response_str == "You rolled 6 and 6 for a total of 12":
await message.channel.send("**Critical Hit!**")
await message.channel.send(response_str)
if response_str == "You rolled 1 and 1 for a total of 2":
await message.channel.send("**Critical Miss!**")
await message.channel.send(response_str)
if message.content.startswith(";roll 3d6"):
response = random.choice(DND_1d6), random.choice(DND_1d6), random.choice(DND_1d6)
response_str = "You rolled {0}, {1} and {2} for a total of {3}".format(response[0], response[1], response[2], sum(response))
if response_str == "You rolled 6, 6 and 6 for a total of 18":
await message.channel.send("**Critical Hit!**")
await message.channel.send(response_str)
if response_str == "You rolled 1, 1 and 1 for a total of 3":
await message.channel.send("**Critical Miss!**")
await message.channel.send(response_str)
This code is essentially copy and pasted to accommodate for multiple 6 sided dice rolls.
I can type ;roll 1d6 and ;roll 2d6, and the commands would work just fine. When I type in ;roll 3d6, the bot doesn't respond. After waiting a few seconds, I tried ;roll 2d6 again, and the bot does not respond at all.
I am not getting any errors in the console, and I do not really know how to debug this. From my eyes, everything looks to be correct. I tried to add 4d6 and 5d6, but the bot does not respond to those commands either.
My only other guess is to implement else and elif's into my code, but I think that would break things.
Thanks in advance for the help!
Aucun commentaire:
Enregistrer un commentaire