2021年3月24日星期三

Why is my discord bot's balance not saving correctly?

My bot works perfectly fine and was working up until I added it to a third discord server. The first server it was in was a bot testing server, then a dead server, and now the actual server it was made for. Everything on the bot is still working except for the wallet bank function. User's balances keep going down. Mine's earlier was 40 and now it's 14? I'm very new to coding and I have no idea why this is happening.

import discord  from discord.ext import commands  import random  import os  import pickle   from keep_alive import keep_alive    client = discord.Client()  client = commands.Bot(command_prefix = ["$", "Shakey"])    dataFilename = "data.pickle"    class Data():    def __init__(self, wallet, bank):      self.wallet = wallet      self.bank = bank     @client.event  async def on_ready():    print ('luck noises')    def loadData():    if os.path.isfile(dataFilename):      with open(dataFilename, "rb") as file:        return pickle.load(file)    else:      return dict()    def loadMemberData(memberID):    data = loadData()      if memberID not in data:      return Data(0, 0)      return data[memberID]    def saveMemberData(memberID, memberData):    data = loadData()      data[memberID] = memberData      with open(dataFilename, "wb") as file:      pickle.dump(data, file)    @client.command(aliases=['p'])  async def ping(ctx):    await ctx.send('Pong!')    @client.command(aliases=['!'])  async def work(message):    memberData = loadMemberData(message.author.id)      memberData.wallet += 1    await message.channel.send("+1 milkshake, keep up the good work.")      saveMemberData(message.author.id, memberData)    @client.command(aliases=['?'])  async def bal(message):    memberData = loadMemberData(message.author.id)      embedVar = discord.Embed(title="{member}'s Balance".format(member=message.author.display_name))    embedVar.add_field(name="Milkshakes", value=str(memberData.wallet))      await message.channel.send(embed=embedVar)     keep_alive()  client.run(os.getenv('TOKEN'))  
https://stackoverflow.com/questions/66792931/why-is-my-discord-bots-balance-not-saving-correctly March 25, 2021 at 12:06PM

没有评论:

发表评论