【问题标题】:Discord.py Error when trying to edit embed after X seconds尝试在 X 秒后编辑嵌入时出现 Discord.py 错误
【发布时间】:2021-04-20 22:24:47
【问题描述】:

所以,经过大约一个小时的尝试,我放弃了。我试图让我的嵌入在 5 秒后得到编辑,但它不起作用。我不断收到此错误:

'''Embed'实例没有'message'成员''

import discord
import random
import asyncio
import time
from discord.ext import commands


class ppsize(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.command(aliases=['mypp', 'sizepp'])
    async def PPPSize(self, ctx):
        responses = [ # Or values, however you want to name it
        'is 2cm.',
        'is 38cm.',
        'is 0cm.',
        'is too small to be measured.',
        '-16cm.',
        'bigger than a whole house.',
        '6cm.',
        'is 9cm',
        'is 13cm'
    ]
        pp = discord.Embed(title="Activating PP Size Measurement...!", description="Loading PP Size...")
        pp.set_image(url="https://tul.imgix.net/content/article/banana.jpg?auto=format,compress&w=1200&h=630&fit=crop")
        pp2 = discord.Embed(title="PP Size Measurement Has Been Activated!", description=random.choice(responses))
        pp2.set_image(url="https://tul.imgix.net/content/article/banana.jpg?auto=format,compress&w=1200&h=630&fit=crop")
        
        await ctx.send(embed=pp)
        await asyncio.sleep(5)
        await pp.message.edit(embed=pp2)



def setup(client):
    client.add_cog(ppsize(client))

相当基本的命令,但不知道该怎么做。我还需要“导入时间”吗?

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:

    您正在尝试编辑嵌入而不是实际发布的消息。

    await pp.message.edit(embed=pp2)
    

    是指嵌入。该嵌入没有名为“消息”的属性,因此出现错误。

    解决这个问题:

    message = await ctx.send(embed=pp)
    await asyncio.sleep(5)
    await message.edit(embed=pp2)   
    

    【讨论】:

      【解决方案2】:

      pp 变量是一个嵌入变量,它没有 message 属性。要获取您可以在发送时分配的消息实例

      message = await ctx.send(embed=pp)
      await asyncio.sleep(5)
      await message.edit(embed=pp2)
      

      PS:你好

      参考:

      【讨论】:

      • 再次感谢您!如此简单的修复仍然无法单独完成......下次必须更加小心。再次感谢您!
      【解决方案3】:

      pp.message.edit(embed=pp2) 说的是 Embed.message.edit() 但正如您的错误所暗示的那样:嵌入上没有消息属性。

      要替换消息中的嵌入,您需要获取最初发送的消息。

      message = await ctx.send(...)
      await message.edit(embed=pp2)
      

      【讨论】:

      • 您在回答中遗漏了一些内容。一方面,ctx.send() 命令需要await 语句。我假设你已经混合了 ctx.messagectx.send() 了?
      • 是的,我混淆了ctx.message 和与ctx.send 关联的新消息。我已经编辑澄清。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2021-01-29
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 2020-02-23
      • 2016-08-09
      相关资源
      最近更新 更多