简体   繁体   English

Discord.py 嵌入覆盖 如何修复它

[英]Discord.py Embed Overriding How to fix it

I want to add another embed msg in my discord,py but it overrides the first one我想在我的 discord,py 中添加另一个嵌入消息,但它会覆盖第一个

from keep_alive import keep_alive
import discord
import os

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_ready():
 await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Avengers Infinity War"))

embed=discord.Embed(title="Nothing! Just lurking :eyes:", color=0x00ffd5) ### <== 1
embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/795599610986627072.gif?v=1")
@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$What are you doing.?'):
       await message.channel.send(embed=embed)

    if message.content.startswith('$Hello'):
       await message.channel.send('Hi!')

    if message.content.startswith('$help'):
       await message.channel.send('```1)$help                                                               2)$Hello                                                                           3)$What are you doing.?```')

embed=discord.Embed(title="Assembling ", color=0x00ffd5) ### <== 2
embed.set_image(url="https://media.discordapp.net/attachments/795596234210934817/795660131547086858/main-qimg-3b0c88bfea0119f0dcb6ebc0de1d5192.gif")
    if message.content.startswith('$Assemble'):
       await message.channel.send(embed=embed)


keep_alive()
client.run(os.getenv('TOKEN'))

The gif (marked by ### <== 1 ) gets replaced by ### <== 2 . gif(由### <== 1标记)被替换为### <== 2

You created the first embed outside of on_message.您在 on_message 之外创建了第一个嵌入。 As a result, you'll get a NameError if the message contains $what are you doing.?因此,如果消息包含$what are you doing.? ,您将收到 NameError。 because the call to send that you have after that if statement tries to access a variable named embed , a variable that was defined outside of the function.因为在 if 语句之后调用send会尝试访问名为embed的变量,该变量是在 function 之外定义的。 You should define that embed in on_message.您应该在 on_message 中定义嵌入。 Also, you can't have two variables named the same thing, because one will overwrite the other.此外,您不能将两个变量命名为相同的东西,因为一个会覆盖另一个。 You might want to rename one of the variables named embed to something else.您可能希望将名为embed的变量之一重命名为其他变量。

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

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