Reputation: 47
I am working on a discord bot that will spit out a random response. Some responses include a die roll.
What I would like is if a random response is give that includes a die roll, for the bot to automatically roll the die.
At the moment I am just trying to get it to respond to itself.
I'm new to python/discord.py so please forgive my ignorance
Basic code:
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
# user types a trigger command
if message.content.startswith('.trigger'):
choice= [
"One of many options, lets roll 1d4"
]
result = random.choice(choice) # I'm doing other bits with the result so hence assigning it to a variable here
await message.channel.send(result)
# If there is the term 1d4 in the choice message, roll the dice
if '1d4' in message.content:
roll = random.randrange(1, 4)
await message.channel.send(f'{"**Result** = "+ str(roll)}')
I don't thing I'm checking to see if the bot is posting the message or anything
Upvotes: 0
Views: 410
Reputation: 47
One of those cases where to figure out the answer, just ask.
Removed the line
if message.author == client.user:
return
And it is working how I wanted
Thanks for being my rubber ducky!
Upvotes: 1