1
1
1AAAhelpmeAAA12022-03-10 19:20:41
Python
1AAAhelpmeAAA1, 2022-03-10 19:20:41

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:

spoiler
Microsoft Windows [Version 6.3.9600]
(c) Корпорация Майкрософт (Microsoft Corporation), 2013. Все права защищены.

C:\Users\User>python "Desktop\для проекта\main.py"
C:\Users\User\Desktop\для проекта\main.py:11: RuntimeWarning: coroutine 'Command
.__call__' was never awaited
print('We have logged in as {0.user}'.format(client))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Ignoring exception in command add:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 706, in _parse_arguments
kwargs[name] = await self.transform(ctx, param)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: content is a required argum
ent that is missing.

when creating the team, open sources were used
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

2 answer(s)
A
Alexander, 2022-03-10
@1AAAhelpmeAAA1

import json
data = {'1':2,'2':3,'3':'Тестовый JSON'}
json.dump(data, open("test.json","w",encoding="utf8"),ensure_ascii=False)

A
Alexander Nesterov, 2022-03-10
@AlexNest

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 question

Ask a Question

731 491 924 answers to any question