通过命令循环发送图像?

问题描述 投票:1回答:1

所以,我想做的是发送有关游戏角色(物品,符文等)的图片,如果用户键入带有角色名称的代码,(?character1)机器人会发送图片。这很简单。

@client.command()
async def character1(ctx):
    await ctx.send(file=discord.File('character1.png'))

@client.command()
async def character2(ctx):
    await ctx.send(file=discord.File('character2.png'))

@client.command
async def character3(ctx):
    await ctx.send(file=discord.File('character3.png'))

但是有很多字符,我想知道我是否可以使用一种方法查看用户发送的命令并检查是否有带有命令名称的图片,然后发送,该方法可以节省一些时间它。因为像在我的示例中一样,除了.png扩展名外,命令和图片的名称都相同。

python discord discord.py
1个回答
0
投票

您可以像这样传递参数:

@client.command()
async def character(ctx, num):
    await ctx.send(file=discord.File(f'character{num}.png'))

这意味着命令格式为:?character 1


参考:

© www.soinside.com 2019 - 2024. All rights reserved.