【发布时间】:2021-07-08 17:38:59
【问题描述】:
所以我试图制作一个用户可以先注册的经济机器人,以便创建一个帐户,这样他们就可以成为经济系统的一部分,现在我试图通过让机器人随机给出赚钱命令通过 5 分钟的冷却时间向发送命令的用户赚取收入,然后我遇到了一个错误,即赚钱命令没有按预期工作,这是完整的代码,问题出在 (getprimo) 上:
@client.command(pass_context=True)
async def wallet(ctx):
id = str(ctx.message.author.id)
if id in amounts:
em1 = discord.Embed(title = f'Wallet', description = "You have {} <:primogem:853895082646044672> in paimon bank <:_Paimon6:827074349450133524>.".format(amounts[id]), color= ctx.author.color)
await ctx.send(embed = em1)
else:
em2 = discord.Embed(title = f'Account Not Registered', description = f'You do not have an account <:_pBaffled:827075083670650950>.\nUse %register to make an account.', color= ctx.author.color)
await ctx.send(embed = em2)
@client.command(pass_context=True)
async def register(ctx):
id = str(ctx.message.author.id)
if id not in amounts:
amounts[id] = 100
em3 = discord.Embed(title = f'Account Successfully Registered', description = f'You are now registered <:_Paimon6:827074349450133524>.', color= ctx.author.color)
await ctx.send(embed = em3)
_save()
else:
em4 = discord.Embed(title = f'Account Already Registered', description = f'You already have an account <:_pBaffled:827075083670650950>.', color= ctx.author.color)
await ctx.send(embed = em4)
@client.command(pass_context=True)
async def send(ctx, other: discord.Member, amount: int):
primary_id = str(ctx.message.author.id)
other_id = str(other.id)
if primary_id not in amounts:
em5 = discord.Embed(title = f'Account Not Registered', description = f'You do not have an account <:_pBaffled:827075083670650950>.\nUse %register to make an account.', color= ctx.author.color)
await ctx.send(embed = em5)
elif other_id not in amounts:
em6 = discord.Embed(title = f'Account Not Registered', description = f'You cant send <:primogem:853895082646044672> to someone that does not have an account.\nTell the person to use %register first in order to send the <:primogem:853895082646044672>.', color= ctx.author.color)
await ctx.send(embed = em6)
elif amounts[primary_id] < amount:
em7 = discord.Embed(title = f'Not Enough Primogems', description = f'Insufficient <:primogem:853895082646044672>.\nCant send <:primogem:853895082646044672> to {other.mention} <:_pHug:827086739435683840>.', color= ctx.author.color)
await ctx.send(embed = em7)
else:
amounts[primary_id] -= amount
amounts[other_id] += amount
em8 = discord.Embed(title = f'Send Successful', description = f'Done sending {amount} <:primogem:853895082646044672> to {other.mention} <:_Paimon6:827074349450133524>.', color= ctx.author.color)
await ctx.send(embed = em8)
_save()
@client.command(pass_context=True)
@commands.cooldown(1, 300, commands.BucketType.user)
async def getprimo(ctx):
id = str(ctx.message.author.id)
amount = random.randrange(0, 100)
amounts[id] += amount
em9 = discord.Embed(title = f'Primogems Earned', description = f'You get {amount} <:primogem:853895082646044672>.\nPlease wait 5 minutes to get more primo <:_Paimon6:827074349450133524>.', color= ctx.author.color)
await ctx.send(embed = em9)
_save()
def _save():
with open('amounts.json', 'w+') as f:
json.dump(amounts, f)
@client.command()
async def save():
_save()
任何帮助将不胜感激,谢谢。
【问题讨论】:
-
您能否提供您遇到问题的代码的完整回溯?它将帮助我们更好地帮助您????
-
@Bagle 当我输入命令时,我的终端中没有错误回溯,它只是空的并且没有工作。
-
您在某处有错误处理程序吗?如果有,暂时注释掉,看看有没有错误
-
没有错误消息,因为其他命令很好,当机器人打开时,机器人在我的终端上使用它的登录通知上线,当我在那里键入 getprimo 命令时,该命令不起作用,该命令应该给用户随机金额的钱,然后它什么也没发生。而且我的终端中也没有错误消息,我的机器人仍然可以完美地运行另一个命令。好吧,这就是我遇到的错误。
-
我不知道如何解决这个错误,要么我的功能错误,要么我缺少一些功能和定义。
标签: python discord.py