为discord.py添加命令参数

时间:2018-10-21 04:28:44

标签: python discord discord.py

因此,我正在制作一个Discord机器人以使用Fortnite API来显示Fortnite统计信息,我已经使用了主要功能(!stats <pc,xbl,psn> <name>),但是我想添加参数“ lastgame”,您可以在!stats之后添加到仅显示最近玩过的游戏(!stats lastgame <platform> <name>)的所有统计信息。我具有api访问权限,并且可以嵌入所有文件,但是我在设置实际参数寄存器时遇到问题。

  if message.content.startswith(COMMAND_PREFIX + 'stats'):
    words = message.content.split(' ', 2)
    word = message.content.split(' ', 1)

    platform = words[1].lower()

    lastgame = word[1].lower()

if platform == 'xbox':
  platform = 'xbl'
elif platform == 'ps4':
  platform = 'psn'
elif lastgame == 'lastgame':
  lastgame = 'lastgame'

    if lastgame in ('lastgame'):
  lastgame = fortnite_api_last(word[1],platform,words[2])

  if lastgame:
    lastdate = lastgame[0]['dateCollected']
    lastkills = lastgame[0]['kills']
    lastscore = lastgame[0]['score']
    lasttop1 = lastgame[0]['top1']
    lasttop3 = lastgame[0]['top3']
    lasttop5 = lastgame[0]['top5']
    lasttop6 = lastgame[0]['top6']
    lasttop10 = lastgame[0]['top10']
    lasttop12 = lastgame[0]['top12']
    lasttop25 = lastgame[0]['top25']

    embed = discord.Embed(title="Fortnite Stats for " + words[2] + "'s Last Game", color=0xc600bc)

    embed.set_footer(text="Stats by BattleDash#3866", icon_url="https://pbs.twimg.com/profile_images/1038570723382415361/wVhgKMug_400x400.jpg")
    embed.add_field(name="Time of Last Game", value='{}\n'.format(lastdate), inline=False)
    embed.add_field(name="Last Kills", value='{}\n'.format(lastkills), inline=False)
    embed.add_field(name="Last Score", value='{}\n'.format(lastscore), inline=False)
    embed.add_field(name="Last Top 1", value='{}\n'.format(lasttop1), inline=False)
    embed.add_field(name="Last Top 3", value='{}\n'.format(lasttop3), inline=False)
    embed.add_field(name="Last Top 5", value='{}\n'.format(lasttop5), inline=False)
    embed.add_field(name="Last Top 6", value='{}\n'.format(lasttop6), inline=False)
    embed.add_field(name="Last Top 10", value='{}\n'.format(lasttop10), inline=False)
    embed.add_field(name="Last Top 12", value='{}\n'.format(lasttop12), inline=False)
    embed.add_field(name="Last Top 25", value='{}\n'.format(lasttop25), inline=False)
    await client.send_message(message.channel, embed=embed)
  else:
    await client.send_message(message.channel, 'Failed to get recentMatches data. Double check spelling of your nickname.')
    await client.send_message(message.channel, 'Usage: ' + COMMAND_PREFIX + 'stats lastgame <pc,xbl,psn> <nickname>')

当前,如果您尝试使用!stats lastgame pc Ninja或其他名称,它将随主要功能Usage: !stats <pc,xbl,psn> <nickname>的用法一起出现

0 个答案:

没有答案