Answer the question
In order to leave comments, you need to log in
Need help with saving data to json file in discord bot based on discord.py. How to do it?
When using the D.add "argument1" command, this error pops up:
import json
import discord
from discord.ext import commands
from datetime import datetime
data = {'1':2,'2':3,'3':'Desktop/users.json'}
json.dump(data, open("Desktop/users.json","w",encoding="utf8"),ensure_ascii=False)
client = discord.ext.commands.Bot(command_prefix = "D.")
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command()
async def add(ctx, *, content:str):
with open("Desktop/users.json","r") as f:
data = json.load(f)
data.append(content)
with open("Desktop/users.json","w") as f:
json.dump(data, f)
@client.command()
async def read(ctx, *, text):
with open("Desktop/users.json","r") as f:
data = json.load(f)
await ctx.send(f'{data}')
@client.command()
async def print(ctx):
now = datetime.now()
s = now.time()
await ctx.send(f'{s}')
@client.command()
async def print1(ctx):
await ctx.send(f"```lol```")
@client.command()
async def prindt(ctx,arg1,arg2,arg3):
a = arg1
b = arg2
c = arg3
if (b) == "*" :
a = int(a) * int(c)
else:
if (b) == "+":
a = int(a) + int(c)
else:
if (b) == "-":
a = int(a) + int(c)
else:
if (b) == "/":
a = int(a) / int(c)
await ctx.send(f'{int(a)}')
client.run('MyToken')
Answer the question
In order to leave comments, you need to log in
import json
data = {'1':2,'2':3,'3':'Тестовый JSON'}
json.dump(data, open("test.json","w",encoding="utf8"),ensure_ascii=False)
Obviously go freelancing. You didn’t really describe the task (or you don’t really understand what you want), you didn’t try to google it, you didn’t try to do it yourself. You won't get much help here. Is that advice:
1. Postpone attempts to make bots.
2.Read documentation/tutorials on python
3.When you learn the basics, analyze what exactly you need and decompose the required task into the smallest possible subtasks.
4. Implement each of them.
5. If something specific does not work out, ask a question.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question