Reputation: 65
I cant get a lot of arguments, I was trying to make an embed generator so I can send embeds right away without having to debug it over and over.
@client.command()
async def embed(ctx, arg1, arg2, arg3, arg4, arg5):
embed=discord.Embed(title="{}".format(arg1), description="{}".format(arg2), color=0xff0000)
embed.set_author(name="{}".format(arg3))
embed.add_field(name="{}".format(arg4), value="{}".format(arg5), inline=True)
embed.set_footer(text=f"Requested by {ctx.author.name}")
await ctx.send(embed=embed)
Upvotes: 0
Views: 618
Reputation: 4680
With commands, you can have as many positional arguments as you want. Each value separated by a space will be passed to the command function as a positional argument. (When invoking the command, quote the input to pass an argument which contains a space.) Command functions can only take one keyword-only argument. On invocation, any input that is not passed to the function as a positional argument is passed as a keyword argument.
@client.command()
async def embed(ctx, title, description, author, name, value):
embed = discord.Embed(title=title, description=desc)
embed.set_author(name=author)
embed.add_field(name=name, value=value, inline=True)
embed.set_footer(text=f"Requested by {ctx.author.name}")
await ctx.channel.send(embed=embed)
For your command (which only has positional arguments), everything should work fine. A sample invocation:
!embed Title "This is a sample description" Author Name "Field value which corresponds to 'name'"
For this invocation, the arguments of embed()
would be as follows:
title="Title"
description="This is a sample description"
author="Author"
name="Name"
value="Field value which corresponds to 'name'"
Note that all positional arguments must be passed on invocation, otherwise an error is thrown. This can be avoided by setting default values to each argument (e.g. async def embed(ctx, title="Embed Title", ...)
)
Check out the documentation for the discord.ext.commands
framework.
Upvotes: 2