Daryl Shyju
Daryl Shyju

Reputation: 1

How to put more than one multi-word variable on discord.py?

@client.command()
async def embed (ctx, title, comma, *, description): 
  await ctx.channel.purge(limit=1) 
  embed = discord.Embed(title = title, description = description)
  embed.set_footer(text="An embed")
  embed.set_author(name = f'{ctx.author.name} says'  , icon_url = ctx.author.avatar_url )
  await ctx.send (embed = embed)

Here, the title should be multiple words and the description must be multiple words. Right now, the title is one word only and the description is multiple words. How do I make it so that both can be multiple words?

Upvotes: 0

Views: 903

Answers (1)

SmartCoder
SmartCoder

Reputation: 52

To take multiple words inside your argument, simply put all of the words into your argument and split it with a comma.

@client.command()
async def embed(ctx, *, args):
  title = args.split(',')[0] # Gets the title by finding index 0
  description = args.split(',')[1]

  embed = discord.Embed(title=title, description=description)
  
  await ctx.send(embed=embed)

Briefly, what this code does is, it splits the args argument into a list using a comma, get the appropriate index for title and description and sends it in a discord.Embed().

Upvotes: 1

Related Questions