简体   繁体   中英

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

In the code below I want the bot to wait for a specific user's message after the command has run. To do that I typed in .esug ("." is the command prefix) and it responded with a message asking me to enter my Minecraft username, but when I entered my username it didn't ask me the second question which it should. Then I checked for errors but there were none and that lead me to here.

Code below:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM