#๐Ÿ”’ Json and discord.py time formatting for a discord bot

73 messages ยท Page 1 of 1 (latest)

faint graniteBOT
#

@ivory heron

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ivory heron
#

I'm a complete beginner in discord.py and json and currently i dont have the time to learn them currently but i've messed around with the code and i got so much errors please someone help me fix this plss

#

i only need help with the time formatting and stuff

#

also dont ask why i use json for a database ๐Ÿ’€

hearty mango
#

what's the error you get exactly?

ivory heron
#

when ppl do ,weekly or ,monthly or ,yearly it incorrectly saves it in the json

#

an there are no timestamps in the json files

#

also its like truncated

#

somewhere among here i think

#

bro ๐Ÿ˜ญ

brave sorrel
#

Any errors? Please include the traceback

hearty mango
ivory heron
#

uh

#

sure

#

one sec

#

its weird

#

wait let me do it safely so that it doesnt mess up ppl's balances

#

ok so for example

#

when i do weekly

#

and dont quit the program everything is fine

#

but if i restart the program and run weekly it doesnt even give a response

brave sorrel
ivory heron
#

bro the whole thing is pretty long

#

like 1000 lines

brave sorrel
#

And?

ivory heron
#

alr sure one sec

brave sorrel
#

Also I see you have something like extensions (I assume this is another separate file right?). Discord.py has a built-in extensions ecosystem which also has the benefit of being able to hot-reload commands. They should be used in conjunction with cogs which are containers for commands (and can also function as categories in the built-in help command)

ivory heron
#

here

brave sorrel
#

And of course I also have to mention how JSON is a data serialization format and it should not be used as a replacement for a proper database, as it can lead to corrupt files under some (somewhat uncommon?) circumstances

ivory heron
#

problem is im too dumb to use sqlite or smt like that ๐Ÿ˜‚

ivory heron
brave sorrel
#

say I have cogs/example.py as follows:

from discord.ext import commands

class Example(commands.Cog):
    @commands.command()
    async def example(self, ctx):
        await ctx.send("this is an example")

async def setup(bot):
    await bot.add_cog(Example())

In my main file I can do the following:

await bot.load_extension('cogs.example') # cogs/example.py becomes cogs.example (like an import)
#

then you can also reload it as ```py
await bot.reload_extension('cogs.example')

brave sorrel
#
  • How do you define your bot class?
  • Do you have any on_command_error/on_error events defined anywhere?
  • How do you run your bot? bot.run? bot.start? If the latter, do you set up logging?
ivory heron
#

ok fine i'll read the docs

brave sorrel
#

THANK YOU

brave sorrel
#

ok can you show me that file?

ivory heron
#

๐Ÿ’€๐Ÿ”ฅ

ivory heron
brave sorrel
#

Where you define/initialize your bot class

#

bot = commands.Bot(...) etc etc

ivory heron
#

oh

#

one sec

#

this is bot.py

#

this is main.py

brave sorrel
#

in that else you should log to console what your error is, for example as follows (which will make it be handled by bot.on_error, and it will log to console):

else:
    raise error
ivory heron
#

like this?

#

bro no way u acc looked through my code ๐Ÿ’€

#

i feel so honored

#

ty bro

#

let me see

#

now look

#

this is js the error

#

console stuff no python code

brave sorrel
#

So, ```py
File "c:\Users\Michael\Programming\Bots\Limbot\economy.py", line 184, in weekly
last_claim_time = datetime.fromisoformat(last_claim_time)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fromisoformat: argument must be str

#

Can you print(last_claim_time) before the if statement inside of the weekly command

#

Ping me next time tho :) I kinda forgot about this since no notifications

#

Your train of thought should be I got an error -> ok which line was it? -> ok there, what is going on there? (use print or other debug tools to figure that out)

faint graniteBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.