I tried to make an get key command to update an github but when i use the command i always get the error “object dict can’t be used in ‘await’ expression” but it still adds the details to the github.
@bot.command()
async def getkey(ctx, roblox_userid: int):
try:
g = Github(GITHUB_GETKEY_TOKEN)
repo = g.get_repo(f'{GITHUB_GETKEY_OWNER}/{GITHUB_GETKEY_REPO}')
file = repo.get_contents(GITHUB_GETKEY_FILE_PATH)
content = file.decoded_content.decode()
new_key = ''.join(random.choices('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', k=5))
expiry_date = (datetime.now() + timedelta(seconds=10)).strftime("%Y-%m-%d %H:%M:%S")
new_entry = f'{{n Key = "{new_key}",n UserId = {roblox_userid},n ExpiryDate = "{expiry_date}"n}},n'
# Find the index of the last closing curly brace
last_brace_index = content.rfind('}')
# Insert the new entry before the last closing curly brace
updated_content = content[:last_brace_index] + new_entry + content[last_brace_index:]
updated_file = repo.get_contents(GITHUB_GETKEY_FILE_PATH) # Fetch the latest file contents
await repo.update_file(updated_file.path, "Adding new key", updated_content, updated_file.sha) # Await the update
await ctx.send(f"Key added successfully. Your new key is: {new_key}")
except Exception as e:
print(f"An error occurred while updating keys.lua: {e}")
await ctx.send("An error occurred while generating the key.")
I tried to use ai to fix it but that failed.
New contributor
Tajae Daniels is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.