Untitled
@bot.command() async def edit(ctx, user: discord.Member, field: str, *value: str): user_id = str(user.id) db = load_database() allowed_user_id = '750515454413635634' allowed_role_id = ROLE_ID if str(ctx.author.id) != allowed_user_id and allowed_role_id not in [role.id for role in ctx.author.roles]: await ctx.send("You do not have permission to use this command.") return # Find the player player = next((p for p in db['players'] if p['discord_id'] == user_id), None) if not player: embed = discord.Embed(description="Player is not registered!", color=0xFFD1DF) await ctx.send(embed=embed) return # Join the *value list to handle multiple-word values (like last name) joined_value = ' '.join(value) try: # Edit the specified field if field.lower() == 'name': player['name'] = joined_value embed = discord.Embed(description=f"{user.mention}'s Name has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'age': player['age'] = int(joined_value) embed = discord.Embed(description=f"{user.mention}'s Age has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() in ['ce', 'energy']: player['energy'] = int(joined_value) embed = discord.Embed(description=f"{user.mention}'s Cursed Energy has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'hp': player['hp'] = int(joined_value) embed = discord.Embed(description=f"{user.mention}'s HP has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'stamina': player['stamina'] = int(joined_value) embed = discord.Embed(description=f"{user.mention}'s Stamina has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'race': player['race'] = joined_value embed = discord.Embed(description=f"{user.mention}'s Race has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'traits': player['traits'] = joined_value embed = discord.Embed(description=f"{user.mention}'s Traits have been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'intelligence': player['intelligence'] = int(joined_value) embed = discord.Embed(description=f"{user.mention}'s Intelligence level has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'image': player['image'] = joined_value embed = discord.Embed(description=f"{user.mention}'s Image has been updated to {joined_value}!", color=0xFFD1DF) elif field.lower() == 'ct': player['ct'] = joined_value embed = discord.Embed(description=f"{user.mention}'s Cursed Technique has been updated to {joined_value}!", color=0xFFD1DF) else: embed = discord.Embed(description="Invalid field. Valid fields are: HP, Stamina, CE/Cursed Energy, Name, Age, Race, Traits, Intelligence, Cursed Technique, Image.", color=0xFFD1DF) await ctx.send(embed=embed) return await ctx.send(embed=embed) # Handle last name (if provided) if len(value) > 1: player['last_name'] = value[-1] # Assign the last word as the last name save_database(db) except ValueError: embed = discord.Embed(description="Invalid value type provided for the field. Ensure numerical fields are given valid numbers.", color=0xFFD1DF) await ctx.send(embed=embed)
Leave a Comment