如何为单个用户discord.py存储项目

2024-09-29 23:23:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的第一个问题,很抱歉,如果它是重复的,我不知道如何用词

我想做的是假设我有一个>;我的命令,它将产生随机数量的硬币从100到500,当我检查>;平衡表显示了该金额,但我希望它仅适用于我,因此当其他人这样做时>;巴尔:如果有意义的话,它将只显示他们开采的数量

这是原始代码

from discord import *
from discord.ext import *
import random
from discord.ext import commands

bot = commands.Bot(command_prefix='>')
coinbalance = 0






@bot.command()
async def mine(ctx):
    coinsget = random.randint(100,500)
    coinstr = str(coinsget)


    global coinbalance
    await ctx.send(":pick: you went mining and collected "+coinstr+" coins!  :moneybag:")
    coinbalance = coinsget + coinbalance

@bot.command()
async def bal(ctx):
    balstr = str(coinbalance)



    await ctx.send("your balance = "+balstr)



bot.run('my token')

这是我试图使用ctx.author的原始版本,但我想不出我能做的任何事情


Tags: fromimportgt数量asyncdefbotrandom

热门问题