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:
JavaScript
x
16
16
1
import discord
2
from datetime import datetime
3
from discord.ext.commands import Bot
4
from discord.ext import commands
5
from discord.ext.commands import has_permissions
6
7
client = commands.Bot(command_prefix='=')
8
9
@client.command(pass_context=True)
10
async def embed(ctx, args):
11
await ctx.channel.purge(limit=1)
12
embed = discord.Embed(color=discord.Colour.red())
13
embed.set_author(name=args)
14
await ctx.send(embed=embed)
15
client.run('YOUR-TOKEN-GOES-HERE')
16
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:
JavaScript
1
2
1
async def embed(ctx, *, args):
2
So your function will look like this:
JavaScript
1
7
1
@client.command(pass_context = True)
2
async def embed(ctx, *, args):
3
await ctx.channel.purge(limit = 1)
4
embed = discord.Embed(color = discord.Colour.red())
5
embed.set_author(name = args)
6
await ctx.send(embed = embed)
7