Python 函数,该函数从json文件返回服务器颜色变量
im tryna使bot为每个服务器都有一个单独的默认嵌入颜色,我没有将相同的长内容粘贴到每个命令中,而是尝试创建一个函数,将变量作为服务器颜色返回,如下所示:Python 函数,该函数从json文件返回服务器颜色变量,python,discord.py,Python,Discord.py,im tryna使bot为每个服务器都有一个单独的默认嵌入颜色,我没有将相同的长内容粘贴到每个命令中,而是尝试创建一个函数,将变量作为服务器颜色返回,如下所示: async def get_color(guildss, ctxx): random = R.choice(discord.Colors) # R is "import random as R" btw red = 0xfa4454 blue = 0x6666e8 green =
async def get_color(guildss, ctxx):
random = R.choice(discord.Colors) # R is "import random as R" btw
red = 0xfa4454
blue = 0x6666e8
green = 0x67fc49
yellow = 0xffff1c
with open("colors.json", "r") as f:
colors = json.load(f)
color = colors[str(guildss.id)]
if color == "amberz":
amberz = 0xe1fc2f
elif color == "red":
amberz = red
elif color == "blue":
amberz = blue
elif color == "green":
amberz = green
elif color == "yellow":
amberz = yellow
elif color == "random":
amberz = random
elif color == "self":
amberz = ctxx.author.color
return amberz
然后命令:
@client.command()
@commands.has_permissions(manage_messages=True)
async def nuke(ctx):
amberz = await get_color(ctx.guild, ctx)
channel = ctx.channel
for channels in ctx.author.guild.channels:
if channels == channel:
await channel.delete()
pos = channel.position
cloned = await ctx.channel.clone()
await cloned.edit(position=pos)
nuked = Embed(title="Boom.", description=f"{cloned.mention} has been nuked.", color=amberz, timestamp=ctx.message.created_at)
nuked.set_image(url="https://media1.tenor.com/images/5b0fcef4b070f5316093ab591e3995a8/tenor.gif?itemid=17383346")
await cloned.send(embed=nuked)
color.json文件如下所示:
{“guild.id”:“amberz”等}
但是它不起作用,我不知道为什么,它也没有给我任何错误,它只是不起任何作用
有人能帮忙吗这只是一个人的事吗?为什么不使用
discord.color.random()
函数?为什么在JSON文件中使用颜色名称?如果您使用颜色代码…@ukaszKwieciński,这样他们就可以更改每个单独服务器的默认嵌入服务器,他们仍然可以。。。