[英]Discord.py - Await for user's message
所以現在我正在嘗試創建一種應用程序機器人,現在我用於機器人的檢查不允許用戶進入下一個問題。 沒有回溯,所以它與我定義的檢查有關。
@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)
現在,在用戶回答第一個問題並且沒有回溯之后,機器人不會做任何事情。
任何幫助或建議都會有很大幫助!
你的支票沒有返回任何東西。 它應該return
True
或False
。 這意味着您的wait_for
永遠不會結束(因為check
永遠不會返回True
),所以它永遠不會問下一個問題。
def check(m):
return m.channel == channel and m.author != self.bot.user
編輯:
您的channel
是ctx.channel
,而您的機器人在 DM 中等待答案。 假設你也在 DM 中回答你的機器人,這意味着你的check
永遠不會通過,因為m.channel
永遠不會等於channel
。
def check(m):
return m.guild is None and m.author == ctx.author
這將檢查是否在 DM 中發送了消息( Guild
為None
),以及它是否是原作者的 DM。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.