python - Discord.py 创建没有字幕的嵌入
问题描述
一般来说,我是 python 和 Stackoverflow 的新手,所以如果这不合适,请告诉我。
问题:如何使用 discord.py 在 discord 中创建嵌入,而无需向嵌入添加子标题?
例如,这是我的 embed 函数的简化版本:
def test_embed():
embedPlacehold = discord.Embed(title='title', color=0xffbf00)
embedPlacehold.add_field(name='sub-title', value='test', inline=False)
return embedPlacehold
我要删除的部分来自第 3 行,name='subtitle
. 但是,.add_field
discord.py 中的函数需要将其作为参数,并且name
不能设置为空字符串。
现在我正在寻找不需要设置字幕的替代功能。我知道其他从 JavaScript 编程的机器人能够发送没有字幕的嵌入,所以我非常肯定在 python 中也有方法可以实现这一点。
我已经浏览了很多网站,但仍然找不到答案,所以我将不胜感激任何可能的帮助!
解决方案
这是一个奇怪的领域,其中 Discord.py 没有意义,至少无法避免或留空,但是有一些方法可以规避这个问题
在此示例中,您可以在不需要的字段中使用粗体装饰器,也可以使用也将显示为空白字段的 unicode 空白字符。
def test_embed():
embedPlacehold = discord.Embed(title='title', color=0xffbf00)
embedPlacehold.add_field(name='sub-title', value='** **', inline=False)
return embedPlacehold
def test_embed():
embedPlacehold = discord.Embed(title='title', color=0xffbf00)
embedPlacehold.add_field(name='sub-title', value='\u200b', inline=False)
return embedPlacehold
Intead,如果你想要一个列表,你可以只使用多行字符串,这会使内容看起来好像没有副标题
def test_embed():
embedPlacehold = discord.Embed(title='title', color=0xffbf00)
embedPlacehold.add_field(name='sub-title', value='''
test
test
test
test
test''', inline=False)
return embedPlacehold