有人可以看看我的代码,因为这东西没有把赠品放在频道里。由于我对 discord.py 还很陌生,我看不出它有什么问题。它显示提出的问题,但在 3 个问题之后它什么也不做。
async def giveaway(ctx):
await ctx.send("? Let's create a new Giveaway! Answer the questions within 15 seconds")
questions = ["Which channel should we host this in?", "What duration should we set for this GA? (S|M|H|D)", "What are we giving away?"]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i, question in enumerate(questions):
embed = Embed(title=f"Question {i+1}", description=question)
await ctx.send(embed=embed)
try:
msg = await bot.wait_for('message', timeout=15.0, check=check)
except asyncio.TimeoutError:
await ctx.send("You didn't respond in time, cancelling")
return
answers.append(msg.content)
try:
c_id = int(answers[0][2:-1])
except:
await ctx.send(f"You didn't mention a channel properly, mention should look like this {ctx.channel.mention} try again?")
return
channel = bot.get_channel(c_id)
time = convert(answers[1])
if time == -1:
await ctx.send("You didn't answer with a proper time unit, please use(S|M|H|D)")
return
elif time == -2:
await ctx.send("The time must be an integer")
return
prize = answers[2]
await ctx.send(f"The giveaway will be in {channel.mention} and will last for {answers[1]}")
embed = discord.Embed(title=":tada: Fun and Free Giveaway! :tada:", description=f"**Prize: **{prize}\n"f"**Hosted By: ** {ctx.author.mention}\n")
embed.add_field(name = "Hosted by:", value = ctx.author.mention)
embed.set_footer(text = f"Ends {answers[1]} from now")
my_msg = await channel.send(embed=embed)
await my_msg.add_reaction("?")
await asyncio.sleep(time)
new_msg = await channel.fetch_message(my_msg.id)
users = await new_msg.reactions[0].users().flatten()
users.pop(users.index(bot.user))
winner = random.choice(users)
await channel.send(f"Congratulations to {winner.mention} you have won {prize}!")```