所以我为一个叫“战场”的机器人创建了货币,简称bp。问题是,我想创建一个商店来购买商品(不必存储),到目前为止,我已经知道了这一点,但不知道如何将其转换为一个命令,如buy name。你知道吗
items = {
"Game1":[3,20],
"Game2":[5,30],
"game3":[5,20],
"game4":[8,10],
}
while True:
print("game1 = 3BP / game2 = 5BP / game3 = 5BP / game4 = 8BP")
print("Account Balance bp",stash)
choice = input("What would you like to buy?: ").strip().title()
if choice in items:
if items[choice][1]>0:
if stash>=items[choice][0]:
items[choice][1]=items[choice][1]-1
stash= stash-items[choice][0]
print("Thank you..!")
print("")
else:
print("Sorry you dont enough money...")
print("")
else:
print("sorry sold out")
print("")
else:
print("Sorry we dont have that item...")
print("")
我试着加入client.commmand()
async def buy():然后是代码,但我似乎无法工作。
你能不能给我指出正确的方向,告诉我在哪里能找到答案,或者你能不能告诉我我做错了什么
我想问题是
choice = input("What would you like to buy?: ").strip().title()
,因为bot不会通过input()
函数接收输入。不过,通常可以将消息的上下文传递给函数。我在你的完整代码中看到:在这里我会注意到
pass_context = True
。这允许函数读取不一致消息的上下文和内容。例如,您可以调用ctx.message.author
来获取被解释消息的作者。所以如果说“Bob Joe”类型“!清除50“,然后:这也应该将
amount
从100改为>50。使用类似的技术,你可以有一个用户“!买金鞋”会触发你的async def buy(ctx, item):
案例:然后由您的逻辑来决定如何处理这些输入,但也许这有助于解释这个过程。如果我不清楚什么,请告诉我。你知道吗
相关问题 更多 >
编程相关推荐