首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TypeError:对象NoneType不能在“await”expression discord.py中使用

TypeError:对象NoneType不能在“await”expression discord.py中使用
EN

Stack Overflow用户
提问于 2020-12-30 00:15:10
回答 1查看 616关注 0票数 0

当我尝试在一个cog TypeError中创建一个命令时,我得到了以下错误: object NoneType不能用在带有代码的'await‘表达式中,并且这个功能很简单当你启动命令时,它会向用户发送一组特定的问题,然后将他们给出的答案返回到命令被启动的嵌入中

代码语言:javascript
运行
复制
import discord
from discord.ext import commands



class Profile(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_ready(self):
        print("Profile Cog has been loaded\n-----")

    # @commands.command(aliases=['pm'])
    # async def dm(self, ctx, user: discord.User, *, message=None):
    #   message = message or "This message is sent via dm"
    #   await user.send(message)
    #   await ctx.message.delete()

    @commands.command()
    async def createprofile(self, ctx, member: discord.Member = None):
        userName = ""
        userAge = ""
        questions = [
            "Please input your name/nickname:",
            "Please input your age:"
        ]
        dmChannel = await ctx.author.send(
            "Yo will be receiving two questions. One involving your name and the other your age.")

        def check(message):
            return message.author == ctx.author and message.channel == dmChannel.channel

        async def askquestion(question):
            await ctx.author.send(question)
            print("Waiting for reply...")
            userReply = await commands.wait_for('message', check=check)
            print("User replied")
            return userReply.content

        userName = await askquestion(questions[0])
        userAge = await askquestion(questions[1])
        e = discord.Embed(title=str(userName) + "'s Profile", description=f"""
        Age: `{str(userAge)}`
        """)
        await ctx.send(embed=e)


def setup(bot):
    bot.add_cog(Profile(bot))
代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "C:\Users\dargo\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\dargo\Desktop\In-Depth\cogs\profile.py", line 42, in createprofile
    userName = await askquestion(questions[0])
  File "C:\Users\dargo\Desktop\In-Depth\cogs\profile.py", line 38, in askquestion
    userReply = await commands.wait_for('message', check=check)
TypeError: object NoneType can't be used in 'await' expression
``
EN

Stack Overflow用户

发布于 2020-12-30 00:29:39

不要在你的参数中使用member: discord.Member = None,而是做一些类似的事情:

member: discord.Member = ""和之后的有效代码中编写示例:

代码语言:javascript
运行
复制
if member == "":
 #do something
else:
 #do something else
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65495221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档