Salutations ! Actuellement j’essaye de créer un bot discord qui serait capable d’enregistrer dans un fichier.json, l’id de l’utilisateur qui effectue la commande : "!Account" Voilà mon code :
import discord
from discord.ext import commands
import json
import os
os.path.exists("C:\\Users\\noe\\Documents\\Personnelle\\Codage\\PythonScripts\\bank")
bot = commands.Bot(command_prefix = "!")
@bot.event
async def on_ready():
print("Ready !")
@bot.command()
async def Account(ctx):
await Open_Account(ctx.author)
async def Open_Account(user):
with open("bank.json","r") as f:
users = json.load(f)
if str(user.id) in users:
return False
else:
users[str(user.id)]
with open("bank.json","r") as f:
json.dump(users,f)
Néanmoins le message d’erreur suivant apparaît dans ma console lors de l’exécution de la commande :
Ignoring exception in command Account:
Traceback (most recent call last):
File "C:\Users\noe\AppData\Local\Programs\Python\Python38\lib\
scord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\noe\Documents\Personnelle\Codage\PythonScripts\
18, in Account
await Open_Account(ctx.author)
File "C:\Users\noe\Documents\Personnelle\Codage\PythonScripts\
21, in Open_Account
with open("bank.json","r") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'bank.js
The above exception was the direct cause of the following except
Traceback (most recent call last):
File "C:\Users\noe\AppData\Local\Programs\Python\Python38\lib\
scord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\noe\AppData\Local\Programs\Python\Python38\lib\
scord\ext\commands\core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\noe\AppData\Local\Programs\Python\Python38\lib\
scord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised a
eNotFoundError: [Errno 2] No such file or directory: 'bank.json'
+0
-0