当我尝试在一个cog TypeError中创建一个命令时,我得到了以下错误: object NoneType不能用在带有代码的'await‘表达式中,并且这个功能很简单当你启动命令时,它会向用户发送一组特定的问题,然后将他们给出的答案返回到命令被启动的嵌入中
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))
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
``
发布于 2020-12-30 00:29:39
不要在你的参数中使用member: discord.Member = None
,而是做一些类似的事情:
在member: discord.Member = ""
和之后的有效代码中编写示例:
if member == "":
#do something
else:
#do something else
https://stackoverflow.com/questions/65495221
复制相似问题