【问题标题】:Discord.py Rainbow EmbedDiscord.py 彩虹嵌入
【发布时间】:2021-03-21 11:52:15
【问题描述】:

我正在创建一个 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...

【问题讨论】:

  • 您是否收到任何错误消息?
  • 首先,在 embed 变量中,您还必须传入标题,所以它不会是:embed = discordEmbed(description=message) 而是:embed = discordEmbed(title=title, description=message)
  • 不,我不需要这样做 title=
  • 好的,但是您是否收到任何错误消息,或者它只是没有做任何事情

标签: python discord.py


【解决方案1】:

简单的彩虹嵌入,每 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 次后不再变色。

【讨论】:

  • 你确定每秒编辑消息 10 次不会让你的 API 被禁止吗?
  • 我看到很多bot都嵌入了彩虹,只听说只有彩虹角色,昵称是禁止的。
  • 您可能每 0.1 秒编辑一次消息就会受到速率限制
  • 是的,这个嵌入每 0.1 秒变化 10 次,然后有 1 秒的中断
【解决方案2】:

这是可能的,但请注意,如果过度使用它,您可能会受到 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")

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-22
    • 2010-11-15
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2019-07-21
    相关资源
    最近更新 更多