Skip to content
Advertisement

How to make an argument on discord.py to be the last words

I am making a discord bot that one of the features is that you can use a command to make the bot embed thing into chat. This is the code:

import discord
from datetime import datetime
from discord.ext.commands import Bot
from discord.ext import commands
from discord.ext.commands import has_permissions

client = commands.Bot(command_prefix='=')

@client.command(pass_context=True)
async def embed(ctx, args):
    await ctx.channel.purge(limit=1)
    embed = discord.Embed(color=discord.Colour.red())
    embed.set_author(name=args)
    await ctx.send(embed=embed)
client.run('YOUR-TOKEN-GOES-HERE')

But when I try to embed more than one words it only embeds the last one. Why does it do that?

Advertisement

Answer

You need to add a * before the final argument to take in the full string like this:

async def embed(ctx, *, args):

So your function will look like this:

@client.command(pass_context = True)
async def embed(ctx, *, args):
    await ctx.channel.purge(limit = 1)
    embed = discord.Embed(color = discord.Colour.red())
    embed.set_author(name = args)
    await ctx.send(embed = embed)
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement