#๐ Json and discord.py time formatting for a discord bot
73 messages ยท Page 1 of 1 (latest)
@ivory heron
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.
here's my paste: https://paste.pythondiscord.com/WBXQ
it deleted my message cus it contained a .txt file
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 ๐
what's the error you get exactly?
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 ๐ญ
Any errors? Please include the traceback
here
can you show an example? sorry, discord bots are hard to run on my own to observe for myself
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
Can you share all of your code? You must have an error getting suppressed silently
And?
alr sure one sec
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)
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
yeah my friend told me that as well
problem is im too dumb to use sqlite or smt like that ๐
what are hot reload commands even lol
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')
I can't find anything too improper here, so I'll be more specific
- How do you define your bot class?
- Do you have any
on_command_error/on_errorevents defined anywhere? - How do you run your bot?
bot.run?bot.start? If the latter, do you set up logging?
what are cogs ๐ญ
ok fine i'll read the docs
THANK YOU
bot.run
ok can you show me that file?
there are no classes
๐๐ฅ
the weekly file?
Line 80 of this, you define an on_command_error but never tell it what to do if it isn't CommandNotFound (your if aint got an else)
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
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
why else would I ask for it lol
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)
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.