如何以更简洁的方式为 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 重写)