在discord.py中显示其他命令对此命令的输入

时间:2020-07-02 18:53:13

标签: python discord.py discord.py-rewrite

我正在开发一个Discord.py机器人,该机器人可以为您提供成员。运作方式如下:

  1. 您键入!find-机器人会发送一个嵌入2或3个服务器的嵌入文件
  2. 加入服务器以获取硬币
  3. 键入!bal
  4. 机器人回复您的余额嵌入
  5. 键入!buy [amount] [ad message]
  6. 当人们键入!find时,您的服务器将弹出并显示一条广告消息

您如何做到这一点,以便在您输入!buy [amount] [ad message]时,人们在输入!find时会得到您的服务器?

这是!buy命令:

@client.command()
async def buy(ctx, price: int, *args):
    link = await ctx.channel.create_invite(max_age = 0)

    advertisement = ' '.join(args)


    findlink = str(link)

    findmessage = str(advertisement)
    findguild = str(ctx.guild)
    findoutput = findguild + '\n' + findlink + '\n' + findmessage


    print(findoutput)

    buyer = str(ctx.message.author.id)


    if buyer not in amounts:
        author = ctx.message.author

        noacc = discord.Embed(
            colour = discord.Colour.blue()
        )

        noacc.set_author(name=f'You do not have an account.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
        noacc.add_field(name='Type "!register" to make an account.', value='\u200b', inline=False)

        await ctx.send(embed=noacc)
    elif amounts[buyer] < price:
        author = ctx.message.author

        notaff = discord.Embed(
            colour = discord.Colour.blue()
        )

        notaff.set_author(name=f'You cannot afford this transaction.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
        notaff.add_field(name='Join some more servers, then try again!', value='\u200b', inline=False)

        await ctx.send(embed=notaff)
    elif price < 5:
        author = ctx.message.author

        larger = discord.Embed(
            colour = discord.Colour.blue()
        )

        larger.set_author(name=f'Amount must be 5 or larger.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
        larger.add_field(name='Sorry!', value='\u200b', inline=False)

        await ctx.send(embed=larger)

    else:

        author = ctx.message.author

        buy = discord.Embed(
            colour = discord.Colour.blue()
        )

        buy.set_author(name=f'Purchased {price} Members.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
        buy.add_field(name='This is what people will see when they type "!find"', value='\u200b', inline=False)
        buy.add_field(name=f"**{ctx.guild}**", value=link, inline=False)
        buy.add_field(name=f'{advertisement}', value='\u200b', inline=False)

        await ctx.send(embed=buy)

        amounts[buyer] -= price

这是!find命令:

@client.command(aliases=['f'])
async def find(ctx):
    global advertisement, findlink, findguild, findmessage

    useravatar = ctx.message.author.avatar

    name = ctx.guild
    link = await ctx.channel.create_invite(max_age = 0)

    author = ctx.message.author

    find = discord.Embed(
        colour = discord.Colour.blue()
    )

    find.set_author(name='Find Servers', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
    find.add_field(name='Do you need help? Join our official help server:', value='\u200b', inline=False)
    find.add_field(name="**iComrade [BOT]** (You won't get any coins from joining this server)", value='https://discord.gg/CMD3aaN', inline=False)
    find.add_field(name=f'Hey {ctx.author.name}, join these servers to get **1 coin each**.', value='\u200b', inline=False)
    find.add_field(name=f'**{name}**', value=f'\n{link}', inline=False)

    await ctx.send(embed=find)

1 个答案:

答案 0 :(得分:0)

简单地制作一本服务器词典,然后一次调用5台服务器就叫一堆服务器。

示例

servers = {}

@bot.command()
async def buy(ctx, amount, *, message):
  server_id = ctx.guild.id
  servers[server_id] = f"{message}"

@bot.command()
async def find(ctx):
  embed = discord.Embed(title="Servers")
  i = 0
  for server in servers:
    name = bot.get_guild(server).name
    value = servers[server]
    embed.add_field(name=f"{name}", value=f"{value}")
    i += 1
    if i == 5:
      break
  await ctx.send(embed=embed)