简体   繁体   English

Discord.py X 秒后尝试编辑嵌入时出错

[英]Discord.py Error when trying to edit embed after X seconds

So, after like an hour of trying I gave up.所以,经过大约一个小时的尝试,我放弃了。 I was trying to make my embed get edited after 5 seconds but it did not work.我试图让我的嵌入在 5 秒后得到编辑,但它没有用。 I keep getting this error:我不断收到此错误:

''Instance of 'Embed' has no 'message' member'' '''嵌入'的实例没有'消息'成员''

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))

Pretty basic command but no clue what to do.非常基本的命令,但不知道该怎么做。 Also do I need the 'Import time'?我还需要“导入时间”吗?

The pp variable is an embed, it doesn't have the message attribute. pp变量是一个嵌入,它没有message属性。 To get the message instance you can assign when sending it要获取您可以在发送时分配的消息实例

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

PS: Hello again PS:再次问好

Reference:参考:

You're trying to edit the embed instead of the actual posted message.您正在尝试编辑嵌入而不是实际发布的消息。

await pp.message.edit(embed=pp2)

is referring to the embed.是指嵌入。 That embed doesn't have an attribute called 'message', hence the error.该嵌入没有名为“消息”的属性,因此出现错误。

To fix this:要解决此问题:

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

pp.message.edit(embed=pp2) is saying Embed.message.edit() but as your error suggests: there is no message attribute on embeds. pp.message.edit(embed=pp2)说的是 Embed.message.edit() 但正如您的错误所暗示的那样:嵌入没有消息属性。

To replace the embed on a message, you need to get the message that was originally sent.要替换消息中的嵌入,您需要获取最初发送的消息。

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

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

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