python - 试图制作一个服务器机器人,但日期时间有问题,我不明白它是什么
问题描述
错误:第 16 行,赠品结束 = datetime.datetime.utcnow() + datetime.timedelta(seconds=mins*60) TypeError: unsupported operand type(s) for *: 'type' and 'int'
我的代码是:
embed = discord.Embed(title= "Giveaway!",description = f"{prize}")
end= datetime.datetime.utcnow() + datetime.timedelta(seconds= mins*60)
embed.add_field(name="Ends In:", value= f"{end} UTC")
embed.set_footer(text=f"Ends {mins} Minutes From Now")
msg = await ctx.send(embed=embed)
await msg.add_reaction('')
await asyncio.sleep(mins*60)
new_msg =await ctx.channel.fetch_message(msg.id)
users = await new_msg.reaction[0].users().flatten()
users.pop(users.index(client.user))
win = random.choice(users)
await ctx.send(f"Congratulations {win.mention} You Just Won {prize}")
解决方案
你的代码没有显示mins
赋值,我认为问题出在mins
变量中,确保它是一个整数并尝试像这样放置括号seconds= (mins*60)
推荐阅读
- python - 在Python中从Excel中获取形状内的文本框值
- react-native - React Native Agora SDK
- c - printf 不会为 int 正确打印 %d 的输出
- javascript - 为什么 React 重新渲染不断发生?
- asp.net-core - PasswordSignInAsync 返回总是失败
- javascript - 获取相同的json数据到root
- javascript - 自定义材质 ui 自动竞争
- node.js - 在 Apollo Graphql 中使用订阅时出错
- swift - 是否有可能快速函数获取
枚举? - php - 这是什么日期格式?2021-10-04T08:19:54.000+04:00