【问题标题】:How can I make my Bot to send a random predefined embed message?如何让我的 Bot 发送随机的预定义嵌入消息?
【发布时间】:2020-06-25 18:36:15
【问题描述】:

每当我运行命令时,它都会按字面意思响应文本,而不是嵌入。这是我的代码:

@client.command()
async def item(ctx):
    items = [
    'embed = discord.Embed(title = "embed1", description = "test1")', 
    'embed = discord.Embed(title = "embed2", description = "test2")']
    randomitem = random.choice(items)
    await ctx.send (randomitem)

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    试试这个:

    @client.command()
    async def item(ctx):
        items = [
        discord.Embed(title = "embed1", description = "test1"), 
        discord.Embed(title = "embed2", description = "test2")]
        randomitem = random.choice(items)
        await ctx.send(embed=randomitem) # embed= - for send discord.Embed
    

    【讨论】:

      【解决方案2】:

      items 列表中填充了字符串,而不是实际的嵌入对象。 所以要得到你想要的结果,你需要像这样删除嵌入对象周围的引号:

      items = [ embed = discord.Embed(title = "embed1", description = "test1"), 
                embed = discord.Embed(title = "embed2", description = "test2")]
      

      因为引号 Python 只是将它们视为字符串。

      编写代码的更好方法是

      items = [discord.Embed(title = "embed1", description = "test1"),
               discord.Embed(title = "embed2", description = "test2")]
      return ctx.send(embed=random.choice(items))
      

      【讨论】:

        猜你喜欢
        • 2021-06-05
        • 2021-04-30
        • 2013-08-13
        • 2021-12-21
        • 2022-01-03
        • 1970-01-01
        • 2020-12-26
        • 2021-12-03
        • 2021-12-25
        相关资源
        最近更新 更多