Python 如何获取嵌入到discord.py中的字段数量?
我正在尝试为我的机器人创建一个帮助命令(有点花哨) 因此,我为命令创建了不同的类别!像这样-Python 如何获取嵌入到discord.py中的字段数量?,python,discord,bots,discord.py,discord.py-rewrite,Python,Discord,Bots,Discord.py,Discord.py Rewrite,我正在尝试为我的机器人创建一个帮助命令(有点花哨) 因此,我为命令创建了不同的类别!像这样- embed = discord.Embed() embed.title = ":computer: **Help Centre: Meta!**" embed.description=":pen_ballpoint: Type `am:[command]` to use a command!" embed.add_field(nam
embed = discord.Embed()
embed.title = ":computer: **Help Centre: Meta!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:hi",value="To say hi to me!")
embed.add_field(name="am:report [issue]",value="To report a bug/issue about the bot!")
embed.add_field(name='am:feedback [feedback\suggestion]',value="To sent a feedback or suggestion to my cretor!")
embed.colour = discord.Colour.green()
embed.set_footer(text="Among Us help centre!")
await ctx.send(embed=embed)
async def wikipe(ctx):
embed = discord.Embed()
embed.title = ":computer: **Help Centre: Wiki!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:wiki [query]",value="To know more about among us game!")
embed.add_field(name="am:find [query]",value="To find anything other than Among Us!")
embed.colour = discord.Colour.green()
embed.set_footer(text="Among Us help centre!")
await ctx.send(embed=embed)
async def tools(ctx):
embed = discord.Embed()
embed.title = ":computer: **Help Centre: Tools!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:dm [@user]\n[message]",value="To send an instant message to anyone from the server!")
embed.colour = discord.Colour.green()
embed.set_footer(text="Among Us help centre!")
await ctx.send(embed=embed)
def fields(cate):
i=0
for emb in cate:
for fields in emb.fields:
i+=1
所以现在我需要每个类别中的字段数(即每个类别中的命令数)!
我做了一个函数。像这样的-
embed = discord.Embed()
embed.title = ":computer: **Help Centre: Meta!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:hi",value="To say hi to me!")
embed.add_field(name="am:report [issue]",value="To report a bug/issue about the bot!")
embed.add_field(name='am:feedback [feedback\suggestion]',value="To sent a feedback or suggestion to my cretor!")
embed.colour = discord.Colour.green()
embed.set_footer(text="Among Us help centre!")
await ctx.send(embed=embed)
async def wikipe(ctx):
embed = discord.Embed()
embed.title = ":computer: **Help Centre: Wiki!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:wiki [query]",value="To know more about among us game!")
embed.add_field(name="am:find [query]",value="To find anything other than Among Us!")
embed.colour = discord.Colour.green()
embed.set_footer(text="Among Us help centre!")
await ctx.send(embed=embed)
async def tools(ctx):
embed = discord.Embed()
embed.title = ":computer: **Help Centre: Tools!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:dm [@user]\n[message]",value="To send an instant message to anyone from the server!")
embed.colour = discord.Colour.green()
embed.set_footer(text="Among Us help centre!")
await ctx.send(embed=embed)
def fields(cate):
i=0
for emb in cate:
for fields in emb.fields:
i+=1
但我犯了个错误,你们谁能帮我一下??
错误是-
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 93, in help
embed.add_field(name="Meta",value = str(fields(meta)))
File "main.py", line 81, in fields
for emb in cate:
TypeError: 'function' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'function' object is not iterable```
出现错误的原因在回溯中说明-您正在尝试迭代函数
因此,无论您在哪里调用
fields()
都会意外地传递一个函数,而不是一个iterable对象(如列表
)。请帮助任何人。那么如何获取字段数?