简体   繁体   English

Discord.py 彩虹嵌入

[英]Discord.py Rainbow Embed

Im creating a Rainbow Embed command but i don't really know how it should work.我正在创建一个 Rainbow Embed 命令,但我真的不知道它应该如何工作。 Maybe you can look and help me create the command :D也许您可以查看并帮助我创建命令:D

Here the code这里的代码

@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...

and Welcome to this Post.和欢迎来到这篇文章。 Im creating a Rainbow Embed command but i dont really know how it should work.我创建了Rainbow Embed命令,但我真的不知道它应该如何工作。 Maybe you can look and help me create the command :D也许您可以查看并帮助我创建命令:D

Here the code这里的代码

@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...

Simple rainbow embed that changes color every 0.1 second:简单的彩虹嵌入,每 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)

After 1000 times embed does not change color anymore.嵌入 1000 次后不再变色。

This is possible however be warned that you can get API limited if overusing this.这是可能的,但是请注意,如果过度使用它,您可能会受到 API 限制。

Import the modules:导入模块:

import discord, asyncio
from discord.ext import commands

Initialize the client and assign colours and delay :初始化客户端并分配coloursdelay

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

Create a command:创建命令:

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

Create and send the embed:创建并发送嵌入:

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

Iterate through each colour 5 times editing the embed every delay seconds:迭代每种颜色 5 次,每delay秒编辑嵌入:

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

Run the bot:运行机器人:

client.run("bot_token")

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM