'Why is the code not running? There is a issue with the json file
I am building a discord bot but it just won't run. I tried everything. Help me! I am building an economy discord bot. I think there is some issue with the lists in the json file. When I run, it says command "" not found. I have tried literally everything. Help me as soon as possible @Python!
import discord
from discord.ext import commands
import random
import json
import os
client = commands.Bot(command_prefix="!")
os.chdir("FOLDER PATH PROVIDED")
@client.event
async def on_ready():
await client.change_presence(activity=discord.Game("In Development"))
print("Ready")
@client.command
async def balance(ctx):
await users(ctx.author)
users = await data()
user = ctx.author
wallet_amount = users[str(user.id)]["Wallet"]
bank_amount = users[str(user.id)]["Bank"]
em = discord.Embed(title="Account")
em.add_field(name="Wallet", value=wallet_amount)
em.add_field(name="Bank", value=bank_amount)
await ctx.send(embed=em)
@client.command
async def beg(ctx):
await account(ctx.author)
users = await data()
user = ctx.author
earning = random.randrange(101)
await ctx.send(f"Someone gave you {earning}")
users[str(user.id)]["Wallet"] = + earning
with open("bank.json") as file:
json.dump(users, file)
async def account(user):
data()
if str(user.id) in users:
return False
else:
users[str(user.id)]["Wallet"] = {}
users[str(user.id)]["Wallet"] = 0
users[str(user.id)]["Bank"] = 0
with open("bank.json") as file:
json.dump(users, file)
return True
async def data():
with open("bank.json") as file:
accounts = json.load(file)
return accounts
client.run("TOKEN PROVIDED")
The json file:
{
}
Solution 1:[1]
you are miss interpreting event and command,
@client.command() is correct..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | KuuHaku |