簡體   English   中英

如何讓 wait_for() 函數在 cogs discord.py 中工作?

[英]How do I make wait_for() function work in cogs discord.py?

在下面的代碼中,我希望機器人在命令運行后等待特定用戶的消息。 為此,我輸入了 .esug(“.”是命令前綴),它回復了一條消息,要求我輸入我的 Minecraft 用戶名,但是當我輸入我的用戶名時,它沒有問我應該的第二個問題。 然后我檢查了錯誤,但沒有錯誤,這將我帶到了這里。

代碼如下:

import e_sugarcane
import discord
from discord.ext import commands

user = discord.Client()

class info_cmds(commands.Cog):
  def __init__(self, bot):
    self.bot = bot

  @commands.command()
  async def esug(self, ctx, name=None, profile=None):
    authorId = ctx.author.id

    if name == None:
      embed2 = discord.Embed(
        color = discord.Color.blue()
      )
      embed2.add_field(name="Missing Information", value="```Please Enter your Minecraft Username```")
      await ctx.send(embed=embed2)

      name = await user.wait_for('message', check=lambda message: message.author == ctx.author)
      print(name)
      profilesList, uuid, boolean = e_sugarcane.listProfiles(name)

      if boolean:
        embed3 = discord.Embed(
          color = discord.Color.blue()
        )
        embed2.add_field(name="Missing Information", value="```Please Enter your SkyBlock Profile Name```")
        await ctx.send(embed=embed3)

        profile = await user.wait_for('message', check=lambda message: message.author == ctx.author)

        profileID = profilesList[profile.lower()]
        totalESugarcane = e_sugarcane.eSugarcane(uuid, profileID)
    else:
      profilesList, uuid, boolean = e_sugarcane.listProfiles(name)
      profileID = profilesList[profile.lower()]
      totalESugarcane = e_sugarcane.eSugarcane(uuid, profileID)


    embed1 = discord.Embed(
      color = discord.Color.blue()
    )

    embed1.add_field(name="Amount of Sugar Cane", value=f"```{str(totalESugarcane)}```")

    await ctx.send(embed=embed1)```

它應該是self.bot.wait_for()而不是user.wait_for()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM