【问题标题】:Stop 2 consecutive uses discord.py停止 2 次连续使用 discord.py
【发布时间】:2022-12-03 20:42:44
【问题描述】:

我正在制作一个可以进行拍卖的不和谐机器人。所以我希望某人只出价一次,除非有人在他/她之后出价。

`async def bid(ctx): 

  embed1=discord.Embed(description= f'Bid has been placed by {ctx.author}', title='bid placed')

  await ctx.send(embed=embed1)

       `

这就是我到目前为止所做的。

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    您可以将作者 ID 放在一个变量中:

    bidderid = 0 #this will reset whenever your bot restarts
    @client.command()
    async def bid(ctx):
        global bidderid
        if ctx.author.id != bidderid: #if it is not the same bidder
            bidderid = ctx.author.id
            embed1=discord.Embed(description= f'Bid has been placed by {ctx.author}', title='bid placed')
            await ctx.send(embed=embed1)
        else: #if it is the same bidder
            await ctx.send('You cannot bid twice in a row!') #replace with whatever message
    

    注意:它不一定是id,你可以存储ctx.author而不是,想法是一样的

    【讨论】:

      【解决方案2】:
      # create an empty list to store user IDs
      user_ids = []
      
      async def bid(ctx):
          # check if the user's ID is in the list of user IDs
          if ctx.author.id in user_ids:
              # if the user has already placed a bid, send a message to let them know
              embed1 = discord.Embed(description= f'{ctx.author}, you have already placed a bid', title='bid not placed')
              await ctx.send(embed=embed1)
          else:
              # if the user has not placed a bid, add their ID to the list of user IDs and send a message to confirm their bid
              user_ids.append(ctx.author.id)
              embed1 = discord.Embed(description= f'Bid has been placed by {ctx.author}', title='bid placed')
              await ctx.send(embed=embed1)
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-08
        • 1970-01-01
        • 1970-01-01
        • 2015-04-14
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        相关资源
        最近更新 更多