所以基本上我正在尝试制作一个投票机器人(受 PollMaster 机器人的启发)并开始制作投票创建向导,但目前任何人都可以回复我的机器人:
#Basic Poll Creation Wizard Command
@client.command(name = 'create')
async def create(context):
#Author Check Function
def check(author):
def inner_check():
if message.author != author:
return False
else:
return True
return inner_check
#Sets The Question For The Poll
setquestion = discord.Embed(title = '**Poll Maker**', color = 0x0f00ff)
author = context.message.author
setquestion.set_footer(text = f'{str(author)[:-5]}\'s poll', icon_url = context.message.author.avatar_url)
setquestion.add_field(name = f'What are you asking?', value = 'What is the question you have, try to be as descriptivve \nas possible without typing an annoying long question.')
await context.message.channel.send(author.mention, embed = setquestion)
question = (await client.wait_for('message', check=check, timeout=30)).content
#Determines Whether Or Not The Author Wants The Poll To be Anonymous
isanonymous = discord.Embed(title = '**Poll Maker**', description = f'Nice, you\'ve got your question; now decide \nwhether or not you want the poll to be anonymous.\n \n`0 - No`\n`1 - Yes`\n \nAn anonymous poll has the following effects: \n:small_blue_diamond: You will never see who voted for which option', color = 0x0f00ff)
isanonymous.set_footer(text = f'{str(author)[:-5]}\'s poll', icon_url = context.message.author.avatar_url)
await context.message.channel.send(author.mention, embed = isanonymous)
anonymous = (await client.wait_for('message', check=check, timeout=30)).content
while True:
try:
anonymous = int(anonymous)
break
except:
await context.message.channel.send(f'{author.mention} **Please enter a valid number (either 0 or 1)**', delete_after = 3)
anonymous = (await client.wait_for('message', check=check, timeout=30)).content
这是我目前所拥有的,我想确保只有原始消息的作者才能回复我的机器人。感谢您的帮助!
答案 0 :(得分:1)
你的检查功能有问题
def check(author):
def inner(message):
return message.author == author
return inner
# To use it
m = await client.wait_for('message', check=check(context.author))
如果你想在没有内部函数的情况下使用它
def check(message):
return message.author == context.author
m = await client.wait_for('message', check=check)