我正在尝试将用户名插入不和谐的嵌入式消息的页脚中,该消息说是谁请求了该命令,但我尝试了各种不同的操作,但无法按照我希望的方式工作。任何帮助,将不胜感激。我希望它进入price
命令
@client.command(pass_context=True)
async def ping(ctx):
username = ctx.message.author.display_name
channel = ctx.message.channel
t1 = time.perf_counter()
await client.send_typing(channel)
t2 = time.perf_counter()
embed=discord.Embed(title="Pong at {username}".format(username=username), description='It took {}ms.'.format(round((t2-t1)*1000)), color=0xDA70D6)
await client.say(embed=embed)
@client.command(aliases= ['price', 'p'])
async def calc(quantity: int, itemA: str, itemB: str):
#itemAPrice = get_value(itemA)
#itemBPrice = get_value(itemB)
itemAPrice = items[aliases[itemA]]
itemBPrice = items[aliases[itemB]]
if itemAPrice and itemBPrice:
itemQuotient = itemAPrice/itemBPrice
itemBEquivalent = round(quantity * itemQuotient, 2)
embed=discord.Embed(title="Exchange Rate", description='{quantity} {itemA} is equal to {itemBEquivalent} {itemB}'.format(quantity = quantity, itemA = itemA, itemBEquivalent = itemBEquivalent, itemB = itemB), color=0xDA70D6)
await client.say(embed=embed)
elif not itemAPrice:
await client.say('No match found for ' + itemA)
elif not itemBPrice:
await client.say('No match found for ' + itemB)
答案 0 :(得分:0)
答案 1 :(得分:0)
将调用上下文传递到命令中,然后使用该上下文获取调用命令的用户的名称。从那里,您可以使用ctx.message.author.name
,并将其插入页脚:
@client.command(aliases= ['price', 'p'], pass_context=True)
async def calc(ctx, quantity: int, itemA: str, itemB: str):
itemAPrice = items[aliases[itemA]]
itemBPrice = items[aliases[itemB]]
if itemAPrice and itemBPrice:
itemQuotient = itemAPrice/itemBPrice
itemBEquivalent = round(quantity * itemQuotient, 2)
embed=discord.Embed(title="Exchange Rate", description='{quantity} {itemA} is equal to {itemBEquivalent} {itemB}'.format(quantity = quantity, itemA = itemA, itemBEquivalent = itemBEquivalent, itemB = itemB), color=0xDA70D6)
embed.set_footer(text="Command invoked by {}".format(ctx.message.author.name))
await client.say(embed=embed)
elif not itemAPrice:
await client.say('No match found for ' + itemA)
elif not itemBPrice:
await client.say('No match found for ' + itemB)
如果要提及用户,则可以改用ctx.message.author.mention