[英]Discord.py - Await for user's message
so right now I'm trying to create a type of application bot and right now the check I used for the bot doesn't allow the user to move onto the next question.所以现在我正在尝试创建一种应用程序机器人,现在我用于机器人的检查不允许用户进入下一个问题。 There is no traceback so it's something with the check I defined.
没有回溯,所以它与我定义的检查有关。
@commands.command()
@commands.has_role("Realm OP")
async def block(self, ctx, user: discord.User):
DMchannel = await ctx.author.create_dm()
channel = ctx.message.channel
author = ctx.message.author
mentions = [role.mention for role in ctx.message.author.roles if role.mentionable]
channel2 = str(channel.name)
channel = channel2.split('-')
if len(channel2) == 2: # #real-emoji
realm, emoji = channel
else: # #realm-name-emoji
realm, emoji = channel[0], channel[-1]
realmName = realm.replace("-" , " ")
realmName1 = realmName.lower()
rolelist = []
print(realmName1)
a = solve(realmName1)
print(a)
realmName2 = str(a) + " OP"
print(realmName2)
check_role = discord.utils.get(ctx.guild.roles, name= realmName2)
if check_role not in ctx.author.roles:
return await ctx.send('You do not own this channel')
else:
await ctx.send("You own this channel!")
def check(m):
return m.channel == channel and m.author != self.bot.user
await DMchannel.send("Please fill out the questions in order to block the user!")
await DMchannel.send("User's Gamertag: (If you don't know, try using the >search command to see if they have any previous records!) ")
blocka1 = await self.bot.wait_for('message', check=check)
await DMchannel.send("Reason for block:")
blocka2 = await self.bot.wait_for('message', check=check)
Right now the bot doesn't do anything after the user responds to the first question and there is no traceback.现在,在用户回答第一个问题并且没有回溯之后,机器人不会做任何事情。
Any help or suggestions would help greatly!任何帮助或建议都会有很大帮助!
Your check isn't returning anything.你的支票没有返回任何东西。 It's supposed to
return
either True
or False
.它应该
return
True
或False
。 This means your wait_for
will never end (as the check
never returns True
), so it will never ask the next question.这意味着您的
wait_for
永远不会结束(因为check
永远不会返回True
),所以它永远不会问下一个问题。
def check(m):
return m.channel == channel and m.author != self.bot.user
EDIT:编辑:
Your channel
is the ctx.channel
, while your bot waits for answers in DM.您的
channel
是ctx.channel
,而您的机器人在 DM 中等待答案。 Assuming you answer your bot in DM as well, this means your check
will never pass, as m.channel
never equals channel
.假设你也在 DM 中回答你的机器人,这意味着你的
check
永远不会通过,因为m.channel
永远不会等于channel
。
def check(m):
return m.guild is None and m.author == ctx.author
This checks if a message was sent in DM ( Guild
is None
), and if it was a DM by the original author.这将检查是否在 DM 中发送了消息(
Guild
为None
),以及它是否是原作者的 DM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.