i have this color command: @commands.group(name = 'color') async def color(self, ctx): if ctx.invoked_subcommand is None: embed1 = discord.Embed(title = 'color', description = 'sets personal color to server by hex code', color=0x303135) embed1.set_author(icon_url=f"{self.bot.user.avatar.url}", name="cope") embed1.add_field(name = f"category", value = f"utility", inline=True) embed1.add_field(name = f"permissions", value = f"none", inline=True) embed1.add_field(name = f"usage", value = f";color set [hex code]\n;color unset```", inline=False)
embed1.add_field(name = f"commands", value = f"color set - sets personal color for you in the server\ncolor unset - unsets the color", inline=False)
embed1.add_field(name = f"aliases", value = f"none", inline=False)
await ctx.send(embed=embed1)
@color.command(name = 'on')
@commands.guild_only()
async def mycor1(self, ctx):
self.color = YES
embed = discord.Embed(description = 'color roles for this server has been enabled', color = red)
await ctx.send(embed=embed)
@color.command(name = 'off')
@commands.guild_only()
async def moor1(self, ctx):
self.color = None
embed = discord.Embed(description = 'color roles for this server has been disabled', color = red)
await ctx.send(embed=embed)
@color.command(name = 'set')
@commands.guild_only()
async def mycolor1(self, ctx, color):
if self.color == None:
return await ctx.send("sorry, this guild has color disabled")
if self.color == YES:
name = f"{ctx.author.name}:color"
if name in [role.name for role in ctx.author.roles]:
embed2 = discord.Embed(description = f'you already have a color', color=0x303135)
return await ctx.send(embed=embed2)
try:
ape = await ctx.guild.create_role(name=f'{ctx.author.name}:color', color=int(f'0x{color}', 16))
await ctx.author.add_roles(ape)
embed = discord.Embed(description = f'{ctx.author.mention} assigned your color to **{color}**', color=int(f'0x{color}', 16))
await ctx.send(embed=embed)
except ValueError:
embed3 = discord.Embed(description = f'invalid hex code', color=0x303135)
return await ctx.send(embed=embed3)
except:
embed4 = discord.Embed(description = f'hex code is too long', color=0x303135)
return await ctx.send(embed=embed4)
@color.command(name = 'unset')
@commands.guild_only()
async def mycolor(self, ctx):
if self.color == None:
return await ctx.send("sorry, this guild has color disabled")
if self.color == YES:
role = discord.utils.get(ctx.message.guild.roles, name=f'{ctx.author.name}:color')
if not role:
embed2 = discord.Embed(description = f'you dont have a color', color=0x303135)
return await ctx.send(embed=embed2)
try:
await role.delete()
embed = discord.Embed(description = f'{ctx.author.mention} removed your color role', color=0x303135)
await ctx.send(embed=embed)
except:
await ctx.send("s")``` and the problem is that self.color is a global command so if i do it in one guild for examle `color off` the color is off for all guilds the bot is in, i made a json database here: ``` @commands.Cog.listener()
async def on_guild_join(self, guild):
with open ('color.json', 'r') as f:
colors = json.load(f)
colors[str(guild.id)] = {}
with open ('color.json', 'w') as f:
json.dump(colors, f, indent=4)``` but the problem is since im in a cog `colors =` wont work in my commands, how can i make colors = work for all my commands? before anyone say it i tried to make a mongo dtabase but idont know how to apply it