如何论证 discord.py 成为遗言

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

我正在制作一个 discord 机器人,其中一个功能是您可以使用命令让机器人将内容嵌入到聊天中。这是代码:

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

但是当我尝试嵌入多个单词时,它只嵌入了最后一个。为什么要这样做?

您需要在最后一个参数之前添加一个 * 以接收完整的字符串,如下所示:

async def embed(ctx, *, args):

因此您的函数将如下所示:

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