用 discord.py 拆分字符串

Splitting strings with discord.py

我想创建一个机器人,它在命令时会输出“(命令中的东西)已给出”。

例如:?give food --> "food was given"

这是我创建这样的东西的微弱尝试(修改了别人的代码)-它不起作用:

@client.command()
async def give(message):
    str = message.content.split(" ")[0].replace("give", "")
    await message.channel.send("**(A) "+str+" was given**")

命令的第一个参数必须始终是 Context 对象,因此我们需要第二个参数作为给定的项目。这里我使用 keyword-only argument 以便它允许空格。

@client.command()
async def give(ctx, *, arg):
    await ctx.send(f"**(A) {arg} was given**")