繁体   English   中英

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

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

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

'''嵌入'的实例没有'消息'成员''

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

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

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

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

PS:再次问好

参考:

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

await pp.message.edit(embed=pp2)

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

要解决此问题:

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

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

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

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

暂无
暂无

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

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