2024-09-27 17:43:37 发布
网友
我现在正在创建一个骰子机器人,想创建一个灵活的命令。例如,'!1d6'(!XdY公司)。 另外,我想创建一个命令,比如'![游戏名][命令]'。例如,'!Cthulhu CBR(50,20)'(因为有很多游戏名,手动添加很困难)。你知道吗
但都有信心,可以实现同样的方式,不知道的方式。 我知道如何添加消息,但我不知道如何添加@client.command命令(). 你知道吗
请告诉我。你知道吗
[我用谷歌翻译。]
import random @client.event async def on_message(message): # Takes in format dice!xdy i.e dice!3d7 rolls 3 d7 dice if (message.content.startswith == 'dice!'): await client.send_message(message.channel, 'Rolling...') diceArr = message.content[5:].split("d") totRolled = 0 for x in range(int(diceArr[0])): totRolled = random.randrange(1, int(diceArr[1]), 1) + totRolled await client.send_message(message.channel, 'Rolled', totRolled)
这样就可以了。我还没有测试它,因为我的Linux笔记本电脑已经死了
非冲突版本:
import random # Takes in format dice!xdy i.e dice!3d7 rolls 3 d7 dice def roll(stri): print('Rolling...') diceArr = stri[5:].split("d") totRolled = 0 for x in range(int(diceArr[0])): totRolled = random.randrange(1, int(diceArr[1]), 1) + totRolled print('Rolled', str(totRolled)) roll("dice!3d7")
这样就可以了。我还没有测试它,因为我的Linux笔记本电脑已经死了
非冲突版本:
相关问题 更多 >
编程相关推荐