From 32478026ee182e4fdfe5441973e49304a6f7062e Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 6 Dec 2022 13:49:45 +0100 Subject: [PATCH] Update code.py --- code/code.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/code.py b/code/code.py index fd68106..31df7c5 100644 --- a/code/code.py +++ b/code/code.py @@ -38,6 +38,11 @@ async def setup(ctx, channel: discord.TextChannel, api_key): except: await ctx.respond("Invalid api key", ephemeral=True) return + #if there is not enough tokens remaining, send a message to the user + if openai.Completion.create(engine="davinci", prompt="Hello world", max_tokens=1).headers["X-RateLimit-Remaining"] == 0: + await ctx.respond("Not enough tokens remaining", ephemeral=True) + debug("Not enough tokens remaining") + return #check if the channel is valid if channel is None: await ctx.respond("Invalid channel id", ephemeral=True)