如何以更简洁的方式为 discord.py 编写嵌入代码?

Posted

技术标签:

【中文标题】如何以更简洁的方式为 discord.py 编写嵌入代码?【英文标题】:How can I write embed code for discord.py in a cleaner way? 【发布时间】:2021-11-17 05:29:31 【问题描述】:

我目前只用一整行编写我的代码。 我已经尝试将它放在多行上,但在使用长值和/描述进行大量嵌入时,它看起来仍然很乱并且占用大量空间 像这样:

import discord

Embed = discord.Embed(title = "Ping", description = my ping is currently something very long and it will take a lot of space for me to write all this information down", colour = discord.Colour.blue())```

【问题讨论】:

btw PEP-8(python 风格指南)建议 names_like_this 用于变量名,NamesLikeThis 用于类名以避免歧义 【参考方案1】:

首先,您的代码无效,因为您错过了引号,但要回答您的问题,您可以将值放入变量中以清理调用并进一步使其更苗条,将字符串拆分为多行:

desc = ("my ping is currently something very long and it will "
        "take a lot of space for me to write all this information down")
blue = discord.Colour.blue()
Embed = discord.Embed(title= "Ping", description= desc, colour= blue)

【讨论】:

【参考方案2】:

怎么样

Embed = discord.Embed(
    title = "Ping",
    description = "My ping is currently something very long and it will" 
                  "take a lot of space for me to write all this information down",
    colour = discord.Colour.blue()
)

【讨论】:

以上是关于如何以更简洁的方式为 discord.py 编写嵌入代码?的主要内容,如果未能解决你的问题,请参考以下文章

Discord Bot 响应短语(Discord.py 重写)

Discord.py:你如何制作按钮?

如何访问discord.py中的哪个语音通道用户写入命令?

在 R 子集设置中不使用子集()并以更简洁的方式使用 [ 来防止拼写错误?

如何将 discord.py 帮助命令放入嵌入中?

如何使用 discord.py 让 discord bot ping 用户 [关闭]