python - 让机器人发送不同的嵌入 discord.py
问题描述
我正在尝试为我的机器人创建一个“帮助”命令,就像 MEE6 作者所做的那样:[MEE6][1] [1]: https://i.stack.imgur.com/Nyehz.png
这是我的代码:
admin = discord.Embed(title='yBot | ADMIN', description='help', color=0x004768)
admin.add_field(name="gruby jestes",value='tak')
MainHelpPage = discord.Embed(title='yBot | HELP', description='help', color=0x004768)
MainHelpPage.add_field(name="Komendy Administracji", value='`.help admin`')
MainHelpPage.set_footer(text="© 2020 - Powered by yanuu ;k#2137")
[...]
bot.remove_command("help")
@bot.command(pass_context=True)
async def help(ctx, *, page=MainHelpPage):
await ctx.send(embed=page)
发送主页完全正常,但是当我想接收“管理员”嵌入时,我收到了这个错误:
Traceback (most recent call last):
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "D:\..python\diskord\discord-test.py", line 97, in on_command_error
raise error
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 851, in invoke
await self.prepare(ctx)
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 786, in prepare
await self._parse_arguments(ctx)
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 706, in _parse_arguments
kwargs[name] = await self.transform(ctx, param)
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 552, in transform
return await self.do_conversion(ctx, converter, argument, param)
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 505, in do_conversion
return await self._actual_conversion(ctx, converter, argument, param)
File "C:\Users\<--->\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 476, in _actual_conversion
raise BadArgument('Converting to "{}" failed for parameter "{}".'.format(name, param.name)) from exc
discord.ext.commands.errors.BadArgument: Converting to "Embed" failed for parameter "page".
关于如何解决它的任何想法?
解决方案
您应该像这样在帮助命令本身中进行嵌入。
@bot.command(pass_context=True)
async def help(ctx, menu_type: str = None):
if menu_type == 'Music':
embed = discord.Embed(title="Music", description="Something", color=0x00ff00)
elif menu_type == "Admin":
embed = discord.Embed(title="Admin", description="Something", color=0x00ff00)
else:
embed = discord.Embed(title="Main", description="Something", color=0x00ff00)
await ctx.send(embed=embed)
推荐阅读
- mysql - MYSQL - 根据列值获取第一条记录
- laravel - Laravel - Laratrust 如何列出团队中所有附加角色的用户?
- msbuild - UE4 ShaderCompileWorker Win64 Development 构建引擎源码时出错
- c# - C# OpenTK“参数 1:无法从 'int' 转换为 'OpenTK.Windowing.Desktop.GameWindowSettings'”
- python - Python - 第一行读取 CSV 不按顺序
- dialogflow-es - 如何在对话流上识别来自谷歌助手的来源?
- c - 在 C 中将三个命令连接在一起
- python - Pandas - 如何对特殊的部分字符串进行分组
- python - 如何使用字典
- pandas - 如何最有效地从 NarrowPeak (BED6+4) 格式文件中检索数据?