【发布时间】:2020-07-20 02:57:25
【问题描述】:
我正在尝试在我的程序中实现一个功能,用户可以使用特定的双面模具添加或减去随机生成的数字。我的代码的基础发布在这里:
import discord
import random
DND_1d20 = range(1, 21)
# Roll d20
if message.content == ";roll 1d20":
response = random.choice(DND_1d20)
response_str = "You rolled {0}".format(response)
if response_str == "You rolled 20":
await message.channel.send("**Critical Hit!**\n You rolled 20")
if response_str == "You rolled 1":
await message.channel.send("**Critical Fail!**\n You rolled 1")
我希望用户能够指定掷骰子“;1d20”但也能够添加“;1d20+(x)”或减去“;1d20-(x)”任何数字 (x)生成的骰子。逻辑看起来像这样
-user ";1d20+2" 假设生成的随机数是 6。由于用户想在我们生成的随机数上加 2,结果是 8。
-bot "你掷出 8"
# Roll d20
if message.content == ";roll 1d20":
response = random.choice(DND_1d20)
response_str = "You rolled {0}".format(response)
if response_str == "You rolled 20":
await message.channel.send("**Critical Hit!**\n You rolled 20")
if response_str == "You rolled 1":
await message.channel.send("**Critical Fail!**\n You rolled 1")
else:
if message.content == "-":
我该怎么做呢?我真的很困惑从哪里开始。我认为上面的代码不正确,因为消息必须完全是“-”。 另外,我将如何合并值 (x),因为它可能是大量数字,或者来自用户输入的 +/- 符号?
感谢任何帮助!
【问题讨论】:
标签: python-3.x bots discord.py dice