使机器人发送不同的嵌入discord.py

时间:2020-11-01 16:55:14

标签: python discord 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".

关于如何解决它的任何想法?

1 个答案:

答案 0 :(得分:0)

您应该像这样在help命令本身中嵌入内容。


@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)