繁体   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