Discord.py彩虹嵌入



我正在创建一个Rainbow Embed命令,但我真的不知道它应该如何工作。也许你可以看看并帮助我创建命令:D

这里的代码

@bot.commands()
async def rainbowembed(ctx, *, message):
embed = discordEmbed(description=message)
ctx.send(embed=embed)
for i in range(5):
# On this point i dont know what to do...
# I want to switch the color of the embed in this format
# 0x3755ff, 0x13ff00, 0xff7400
# and i want to repeat it 5 times, so it goes 5 times trough this Colors...

每0.1秒改变颜色的简单彩虹嵌入:

@client.command()
async def rainbow(ctx): 

cols = [0x32a852, 0x3296a8, 0xb700ff, 0x9232a8, 0xa8326f, 0xf25207, 0x3efa00, 0xfa0000]
embed = discord.Embed(
title = "RAINBOW",
color = random.choice(cols)
)
msg = await ctx.send(embed=embed)
for i in range(1000):
embed2 = discord.Embed(
title = "RAINBOW",
color = random.choice(cols)
)
await asyncio.sleep(0.1)
await msg.edit(embed=embed2)

1000次嵌入后不再变色。

但是,如果过度使用,可能会限制API。

导入模块:

import discord, asyncio
from discord.ext import commands

初始化客户端并分配coloursdelay:

client = discord.ext.commands.Bot(command_prefix = "!")
colours = [0x3755ff, 0x13ff00, 0xff7400]
delay = 1

创建命令:

@client.command()
async def rainbowembed(ctx, *, message):

创建并发送嵌入:

embed = discord.Embed(description=message)
msg = await ctx.send(embed=embed)

delay秒遍历每种颜色5次编辑嵌入:

for i in range(5):
for colour in colours:
await msg.edit(embed=discord.Embed(description=message, colour=colour))
await asyncio.sleep(delay)

运行机器人:

client.run("bot_token")

参考文献:

  • discord.Embed
  • discord.Message.edit
  • asyncio.sleep()

最新更新