gpt4 book ai didi

python - 在 Python 中编写 Discord 机器人 - 如何使嵌入具有随机颜色?

转载 作者:行者123 更新时间:2023-12-04 00:51:41 25 4
gpt4 key购买 nike

我正在尝试让它每当机器人发送嵌入时,它的颜色都是随机的。这是我的代码:

colors = ['0xFFE4E1', '0x00FF7F', '0xD8BFD8', '0xDC143C', '0xFF4500', '0xDEB887', '0xADFF2F', '0x800000', '0x4682B4', '0x006400', '0x808080', '0xA0522D', '0xF08080', '0xC71585', '0xFFB6C1', '0x00CED1']

@client.command(help='Shares a meme')
async def meme(ctx):
subreddit = reddit.subreddit("dankmemes")
all_subs = []
top = subreddit.top(limit = 75)

for submission in top:
all_subs.append(submission)

random_sub = random.choice(all_subs)
name = random_sub.title
url = random_sub.url
em = discord.Embed(title = name, color = random.choice(colors))

em.set_image(url = url)
await ctx.send(embed = em)

它给了我这个错误:TypeError: Expected discord.Colour, int, or Embed.Empty but received str instead.

不知道如何解决这个问题,有什么提示吗?

最佳答案

我猜,应该是

colors = [0xFFE4E1, 0x00FF7F, 0xD8BFD8, 0xDC143C, 0xFF4500, 0xDEB887, 0xADFF2F, 0x800000, 0x4682B4, 0x006400, 0x808080, 0xA0522D, 0xF08080, 0xC71585, 0xFFB6C1, 0x00CED1]

关于python - 在 Python 中编写 Discord 机器人 - 如何使嵌入具有随机颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65867118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com